Skip to content

Commit ab02ad0

Browse files
committed
Small cleanup in export_info_functions
� Conflicts: � godot-core/src/registry/property/mod.rs
1 parent 9da0f54 commit ab02ad0

File tree

3 files changed

+21
-23
lines changed

3 files changed

+21
-23
lines changed

godot-core/src/registry/property/mod.rs

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ use crate::classes;
1616
use crate::global::PropertyHint;
1717
use crate::meta::{ClassName, FromGodot, GodotConvert, GodotType, PropertyHintInfo, ToGodot};
1818
use crate::obj::{EngineEnum, GodotClass};
19-
20-
mod phantom_var;
21-
22-
pub use phantom_var::PhantomVar;
23-
2419
// ----------------------------------------------------------------------------------------------------------------------------------------------
2520
// Trait definitions
2621

@@ -236,11 +231,13 @@ pub mod export_info_functions {
236231
use crate::meta::{GodotType, PropertyHintInfo, PropertyInfo};
237232
use crate::obj::EngineEnum;
238233
use crate::registry::property::Export;
234+
use crate::sys;
235+
use std::fmt::Write;
239236

240237
/// Turn a list of variables into a comma separated string containing only the identifiers corresponding
241238
/// to a true boolean variable.
242239
macro_rules! comma_separate_boolean_idents {
243-
($( $ident:ident),* $(,)?) => {
240+
($( $ident:ident ),* $(,)?) => {
244241
{
245242
let mut strings = Vec::new();
246243

@@ -261,7 +258,8 @@ pub mod export_info_functions {
261258
/// You'll never call this function itself, but will instead use the macro `#[export(range=(...))]`, as below. The syntax is
262259
/// very similar to Godot's [`@export_range`](https://docs.godotengine.org/en/stable/classes/class_%40gdscript.html#class-gdscript-annotation-export-range).
263260
/// `min`, `max`, and `step` are `f32` positional arguments, with `step` being optional and defaulting to `1.0`. The rest of
264-
/// the arguments can be written in any order. The symbols of type `bool` just need to have those symbols written, and those of type `Option<T>` will be written as `{KEY}={VALUE}`, e.g. `suffix="px"`.
261+
/// the arguments can be written in any order. The symbols of type `bool` just need to have those symbols written, and those of type
262+
/// `Option<T>` will be written as `{KEY}={VALUE}`, e.g. `suffix="px"`.
265263
///
266264
/// ```
267265
/// # use godot::prelude::*;
@@ -307,18 +305,19 @@ pub mod export_info_functions {
307305

308306
let mut hint_string = hint_beginning;
309307
if !rest.is_empty() {
310-
hint_string.push_str(&format!(",{rest}"));
308+
write!(hint_string, ",{rest}").unwrap();
311309
}
312310
if let Some(suffix) = suffix {
313-
hint_string.push_str(&format!(",suffix:{suffix}"));
311+
write!(hint_string, ",suffix:{suffix}").unwrap();
314312
}
315313

316314
PropertyHintInfo {
317315
hint: PropertyHint::RANGE,
318-
hint_string: GString::from(&hint_string),
316+
hint_string: GString::from(hint_string),
319317
}
320318
}
321319

320+
// See also godot-macros > c_style_enum.rs; some code duplication.
322321
#[doc(hidden)]
323322
pub struct ExportValueWithKey<T> {
324323
variant: String,
@@ -339,23 +338,19 @@ pub mod export_info_functions {
339338
where
340339
for<'a> &'a V: Into<Self>,
341340
{
342-
let values = values
343-
.iter()
344-
.map(|v| v.into().as_hint_string())
345-
.collect::<Vec<_>>();
346-
347-
values.join(",")
341+
sys::join_with(values.iter(), ",", |v| (*v).into().as_hint_string())
348342
}
349343
}
350344

345+
/// Allows syntax `("name", None)` and `("name", Some(10))`.
351346
impl<T, S> From<&(S, Option<T>)> for ExportValueWithKey<T>
352347
where
353348
T: Clone,
354349
S: AsRef<str>,
355350
{
356351
fn from((variant, key): &(S, Option<T>)) -> Self {
357352
Self {
358-
variant: variant.as_ref().into(),
353+
variant: variant.as_ref().to_string(),
359354
key: key.clone(),
360355
}
361356
}
@@ -381,7 +376,7 @@ pub mod export_info_functions {
381376

382377
PropertyHintInfo {
383378
hint: PropertyHint::ENUM,
384-
hint_string: GString::from(&hint_string),
379+
hint_string: GString::from(hint_string),
385380
}
386381
}
387382

@@ -390,7 +385,7 @@ pub mod export_info_functions {
390385

391386
PropertyHintInfo {
392387
hint: PropertyHint::EXP_EASING,
393-
hint_string: GString::from(&hint_string),
388+
hint_string: GString::from(hint_string),
394389
}
395390
}
396391

@@ -414,7 +409,7 @@ pub mod export_info_functions {
414409

415410
PropertyHintInfo {
416411
hint: PropertyHint::FLAGS,
417-
hint_string: GString::from(&hint_string),
412+
hint_string: GString::from(hint_string),
418413
}
419414
}
420415

@@ -493,7 +488,7 @@ pub mod export_info_functions {
493488

494489
PropertyHintInfo {
495490
hint: PropertyHint::TYPE_STRING,
496-
hint_string: GString::from(&format!("{hint_string}:{filter}")),
491+
hint_string: GString::from(format!("{hint_string}:{filter}")),
497492
}
498493
}
499494

godot-ffi/src/toolbox.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ where
177177
// String formatting by itself is an infallible operation.
178178
// Read more at: https://doc.rust-lang.org/stable/std/fmt/index.html#formatting-traits
179179
write!(&mut result, "{first}", first = format_elem(&first))
180-
.expect("Formatter should not fail!");
180+
.expect("formatter should not fail");
181+
181182
for item in iter {
182183
write!(&mut result, "{sep}{item}", item = format_elem(&item))
183-
.expect("Formatter should not fail!");
184+
.expect("formatter should not fail");
184185
}
185186
}
186187
result

godot-macros/src/derive/data_models/c_style_enum.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ impl CStyleEnum {
122122

123123
/// Return a hint string for use with `PropertyHint::ENUM` where the variants are just kept as strings.
124124
pub fn to_string_hint(&self) -> TokenStream {
125+
// See also export_info_functions::slice_as_hint_string(), some code duplication.
126+
125127
let hint_string = self
126128
.enumerator_names
127129
.iter()

0 commit comments

Comments
 (0)