Skip to content

Commit

Permalink
Use new format macro syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
chitoyuu committed Dec 7, 2022
1 parent ce18d8c commit cff27a3
Show file tree
Hide file tree
Showing 44 changed files with 113 additions and 176 deletions.
2 changes: 1 addition & 1 deletion bindings-generator/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ mod tests {
];
tests.iter().for_each(|(class_name, expected)| {
let actual = module_name_from_class_name(class_name);
assert_eq!(*expected, actual, "Input: {}", class_name);
assert_eq!(*expected, actual, "Input: {class_name}");
});
}
}
29 changes: 6 additions & 23 deletions bindings-generator/src/class_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,10 @@ impl GodotXmlDocs {
if let Some(property_name) = node.attribute("name") {
if !property_name.contains('/') {
if node.has_attribute("setter") {
self.add_fn(
class,
&format!("set_{}", property_name),
desc,
&[],
);
self.add_fn(class, &format!("set_{property_name}"), desc, &[]);
}
if node.has_attribute("getter") {
self.add_fn(
class,
&format!("get_{}", property_name),
desc,
&[],
);
self.add_fn(class, &format!("get_{property_name}"), desc, &[]);
}
}
}
Expand Down Expand Up @@ -187,10 +177,7 @@ impl GodotXmlDocs {

// Info for GDScript blocks
let godot_doc = if godot_doc.contains("[codeblock]") {
format!(
"_Sample code is GDScript unless otherwise noted._\n\n{}",
godot_doc
)
format!("_Sample code is GDScript unless otherwise noted._\n\n{godot_doc}")
} else {
godot_doc
};
Expand All @@ -213,9 +200,9 @@ impl GodotXmlDocs {
let text = &c[2];

if text.is_empty() {
format!("<{url}>", url = url)
format!("<{url}>")
} else {
format!("[{text}]({url})", text = text, url = url)
format!("[{text}]({url})")
}
});

Expand Down Expand Up @@ -247,11 +234,7 @@ impl GodotXmlDocs {
let godot_ty = &c[2];
let rust_ty = Self::translate_type(godot_ty);

format!(
"[`{godot_ty}`][{rust_ty}]",
godot_ty = godot_ty,
rust_ty = rust_ty
)
format!("[`{godot_ty}`][{rust_ty}]")
});

godot_doc.to_string()
Expand Down
2 changes: 1 addition & 1 deletion bindings-generator/src/documentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ fn list_base_classes(output: &mut impl Write, api: &Api, parent_name: &str) -> G
if let Some(parent) = api.find_class(parent_name) {
let class_link = class_doc_link(parent);

writeln!(output, " - {}", class_link)?;
writeln!(output, " - {class_link}")?;

if !parent.base_class.is_empty() {
list_base_classes(output, api, &parent.base_class)?;
Expand Down
7 changes: 1 addition & 6 deletions bindings-generator/src/godot_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ pub fn parse_godot_version(version_str: &str) -> Result<GodotVersion, Box<dyn Er

let caps = regex.captures(version_str).ok_or("Regex capture failed")?;

let fail = || {
format!(
"Version substring could not be matched in '{}'",
version_str
)
};
let fail = || format!("Version substring could not be matched in '{version_str}'");

Ok(GodotVersion {
major: caps.get(1).ok_or_else(fail)?.as_str().parse::<u8>()?,
Expand Down
2 changes: 1 addition & 1 deletion bindings-generator/src/methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ pub fn generate_method_table(api: &Api, class: &GodotClass) -> TokenStream {
} = m.get_name();

let rust_ident = format_ident!("{}", rust_name);
let original_name = format!("{}\0", original_name);
let original_name = format!("{original_name}\0");

if !skip_method(m, rust_name) {
assert!(original_name.ends_with('\0'), "original_name must be null terminated");
Expand Down
2 changes: 1 addition & 1 deletion bindings-generator/src/special_methods.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub fn generate_singleton_getter(class: &GodotClass) -> TokenStream {
class.name.as_ref()
};

let singleton_name = format!("{}\0", s_name);
let singleton_name = format!("{s_name}\0");

assert!(
singleton_name.ends_with('\0'),
Expand Down
2 changes: 1 addition & 1 deletion gdnative-async/src/method.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ impl<C: NativeClass, F: AsyncMethod<C>> Method<C> for Async<F> {
Some(Err(err)) => {
log::error(
Self::site().unwrap_or_default(),
format_args!("unable to spawn future: {}", err),
format_args!("unable to spawn future: {err}"),
);
Variant::nil()
}
Expand Down
4 changes: 2 additions & 2 deletions gdnative-async/src/rt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ pub fn register_runtime_with_prefix<S>(handle: &InitHandle, prefix: S)
where
S: Display,
{
handle.add_class_as::<bridge::SignalBridge>(format!("{}SignalBridge", prefix));
handle.add_class_as::<func_state::FuncState>(format!("{}FuncState", prefix));
handle.add_class_as::<bridge::SignalBridge>(format!("{prefix}SignalBridge"));
handle.add_class_as::<func_state::FuncState>(format!("{prefix}FuncState"));
}

/// Releases all observers still in use. This should be called in the
Expand Down
7 changes: 3 additions & 4 deletions gdnative-bindings/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,15 @@ fn generate(
for (class, code) in &binding_res.class_bindings {
let mod_name = gen::module_name_from_class_name(&class.name);

let mod_path = out_path.join(format!("{}.rs", mod_name));
let mod_path = out_path.join(format!("{mod_name}.rs"));
let mut mod_output = BufWriter::new(File::create(&mod_path).unwrap());

write!(
&mut mod_output,
r#"
{content}
{code}
use super::*;
"#,
content = code,
)
.unwrap();

Expand Down Expand Up @@ -152,7 +151,7 @@ fn format_file_if_needed(output_rs: &Path) {
Ok(_) => println!("Done."),
Err(err) => {
println!("Failed.");
println!("Error: {}", err);
println!("Error: {err}");
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/byte_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@ godot_test!(
godot_test!(
test_byte_array_debug {
let arr = (0..8).collect::<ByteArray>();
assert_eq!(format!("{:?}", arr), "[0, 1, 2, 3, 4, 5, 6, 7]");
assert_eq!(format!("{arr:?}"), "[0, 1, 2, 3, 4, 5, 6, 7]");
}
);
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/color_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ godot_test!(
Color::from_rgb(0.0, 0.0, 1.0),
]);

assert_eq!(format!("{:?}", arr), "[Color { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, Color { r: 0.0, g: 1.0, b: 0.0, a: 1.0 }, Color { r: 0.0, g: 0.0, b: 1.0, a: 1.0 }]");
assert_eq!(format!("{arr:?}"), "[Color { r: 1.0, g: 0.0, b: 0.0, a: 1.0 }, Color { r: 0.0, g: 1.0, b: 0.0, a: 1.0 }, Color { r: 0.0, g: 0.0, b: 1.0, a: 1.0 }]");
}
);
3 changes: 1 addition & 2 deletions gdnative-core/src/core_types/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -578,8 +578,7 @@ godot_test!(test_dictionary {
assert_eq!(Some(value), dict.get(&key));
assert!(
iter_keys.insert(key.to_string()) ,
"key is already contained in set: {:?}",
key
"key is already contained in set: {key:?}"
);
}
assert_eq!(expected_keys, iter_keys);
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ impl GodotError {
impl std::fmt::Display for GodotError {
#[inline]
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Godot API error: {:?}", self)
write!(f, "Godot API error: {self:?}")
}
}

Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/float32_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,6 @@ godot_test!(
godot_test!(
test_float32_array_debug {
let arr = (0..8).map(|i| i as f32).collect::<Float32Array>();
assert_eq!(format!("{:?}", arr), "[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]");
assert_eq!(format!("{arr:?}"), "[0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0]");
}
);
4 changes: 1 addition & 3 deletions gdnative-core/src/core_types/geom/transform2d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,6 @@ fn test_transform2d_constructor() {
let expected_local_right = Vector2::RIGHT.rotated(-rotation) * scale;
assert!(
actual_local_right.is_equal_approx(expected_local_right),
"{:?} != {:?}",
actual_local_right,
expected_local_right
"{actual_local_right:?} != {expected_local_right:?}"
);
}
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/int32_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ godot_test!(
godot_test!(
test_int32_array_debug {
let arr = (0..8).collect::<Int32Array>();
assert_eq!(format!("{:?}", arr), "[0, 1, 2, 3, 4, 5, 6, 7]");
assert_eq!(format!("{arr:?}"), "[0, 1, 2, 3, 4, 5, 6, 7]");
}
);
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/string_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ godot_test!(
GodotString::from("baz"),
]);

assert_eq!(format!("{:?}", arr), "[\"foo\", \"bar\", \"baz\"]");
assert_eq!(format!("{arr:?}"), "[\"foo\", \"bar\", \"baz\"]");
}
);
39 changes: 16 additions & 23 deletions gdnative-core/src/core_types/variant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ impl FromVariantError {
/// Returns a `FromVariantError` with a custom message.
#[inline]
pub fn custom<T: fmt::Display>(message: T) -> Self {
FromVariantError::Custom(format!("{}", message))
FromVariantError::Custom(format!("{message}"))
}
}

Expand All @@ -939,78 +939,71 @@ impl fmt::Display for FromVariantError {

match self {
E::Unspecified => write!(f, "unspecified error"),
E::Custom(s) => write!(f, "{}", s),
E::Custom(s) => write!(f, "{s}"),
E::InvalidNil => write!(f, "expected non-nullable type, got null"),
E::InvalidVariantType {
variant_type,
expected,
} => write!(
f,
"invalid variant type: expected {:?}, got {:?}",
expected, variant_type
"invalid variant type: expected {expected:?}, got {variant_type:?}"
),
E::CannotCast { class, to } => {
write!(f, "cannot cast object of class {} to {}", class, to)
write!(f, "cannot cast object of class {class} to {to}")
}
E::InvalidLength { len, expected } => {
write!(f, "expected collection of length {}, got {}", expected, len)
write!(f, "expected collection of length {expected}, got {len}")
}
E::InvalidEnumRepr { expected, error } => write!(
f,
"invalid enum representation: expected {:?}, {}",
expected, error
"invalid enum representation: expected {expected:?}, {error}"
),
E::InvalidStructRepr { expected, error } => write!(
f,
"invalid struct representation: expected {:?}, {}",
expected, error
"invalid struct representation: expected {expected:?}, {error}"
),
E::UnknownEnumVariant { variant, expected } => {
write!(
f,
"unknown enum variant {}, expected variants are: ",
variant
)?;
write!(f, "unknown enum variant {variant}, expected variants are: ")?;
let mut first = true;
for v in *expected {
if first {
first = false;
} else {
write!(f, ", ")?;
}
write!(f, "{}", v)?;
write!(f, "{v}")?;
}
Ok(())
}
E::InvalidEnumVariant { variant, error } => {
write!(f, "invalid value for variant {}: {}", variant, error)
write!(f, "invalid value for variant {variant}: {error}")
}
E::InvalidInstance { expected } => {
write!(f, "object is not an instance of `NativeClass` {}", expected)
write!(f, "object is not an instance of `NativeClass` {expected}")
}
E::InvalidField { field_name, error } => {
write!(f, "invalid value for field {}", field_name)?;
write!(f, "invalid value for field {field_name}")?;

let mut next_error = error.as_ref();
loop {
match next_error {
E::InvalidField { field_name, error } => {
write!(f, ".{}", field_name)?;
write!(f, ".{field_name}")?;
next_error = error.as_ref();
}
E::InvalidItem { index, error } => {
write!(f, "[{}]", index)?;
write!(f, "[{index}]")?;
next_error = error.as_ref();
}
_ => {
write!(f, ": {}", next_error)?;
write!(f, ": {next_error}")?;
return Ok(());
}
}
}
}
E::InvalidItem { index, error } => {
write!(f, "invalid value for item at index {}: {}", index, error)
write!(f, "invalid value for item at index {index}: {error}")
}
}
}
Expand Down
12 changes: 3 additions & 9 deletions gdnative-core/src/core_types/variant/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl<'de> Visitor<'de> for VariantTypeVisitor {
if value < VariantType::NAMES.len() as u64 {
Ok(VariantType::from_sys(value as sys::godot_variant_type))
} else {
Err(E::custom(&*format!("invalid VariantType value: {}", value)))
Err(E::custom(&*format!("invalid VariantType value: {value}")))
}
}

Expand All @@ -39,10 +39,7 @@ impl<'de> Visitor<'de> for VariantTypeVisitor {
return Ok(VariantType::from_sys(i as sys::godot_variant_type));
}
}
Err(E::custom(&*format!(
"invalid VariantType value: {:?}",
value
)))
Err(E::custom(&*format!("invalid VariantType value: {value:?}")))
}

#[inline]
Expand All @@ -55,10 +52,7 @@ impl<'de> Visitor<'de> for VariantTypeVisitor {
return Ok(VariantType::from_sys(i as sys::godot_variant_type));
}
}
Err(E::custom(&*format!(
"invalid VariantType value: {:?}",
value
)))
Err(E::custom(&*format!("invalid VariantType value: {value:?}")))
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/variant_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,7 +617,7 @@ godot_test!(
arr.push(&Variant::new(true));
arr.push(&Variant::new(42));

assert_eq!(format!("{:?}", arr), "[GodotString(hello world), Bool(True), I64(42)]");
assert_eq!(format!("{arr:?}"), "[GodotString(hello world), Bool(True), I64(42)]");

let set = catch_unwind(|| { arr.set(3, 7i64); });
let get = catch_unwind(|| { arr.get(3); });
Expand Down
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/vector2_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,6 @@ godot_test!(
Vector2::new(5.0, 6.0),
]);

assert_eq!(format!("{:?}", arr), format!("{:?}", &[Vector2::new(1.0, 2.0), Vector2::new(3.0, 4.0), Vector2::new(5.0, 6.0)]));
assert_eq!(format!("{arr:?}"), format!("{:?}", &[Vector2::new(1.0, 2.0), Vector2::new(3.0, 4.0), Vector2::new(5.0, 6.0)]));
}
);
2 changes: 1 addition & 1 deletion gdnative-core/src/core_types/vector3_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,6 @@ godot_test!(
Vector3::new(5.0, 6.0, 7.0),
]);

assert_eq!(format!("{:?}", arr), format!("{:?}", &[Vector3::new(1.0, 2.0, 3.0), Vector3::new(3.0, 4.0, 5.0), Vector3::new(5.0, 6.0, 7.0)]));
assert_eq!(format!("{arr:?}"), format!("{:?}", &[Vector3::new(1.0, 2.0, 3.0), Vector3::new(3.0, 4.0, 5.0), Vector3::new(5.0, 6.0, 7.0)]));
}
);
Loading

0 comments on commit cff27a3

Please sign in to comment.