Skip to content

Commit

Permalink
Update all usages to #[init(val = ...)] syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Bromeon committed Aug 7, 2024
1 parent ba20a8b commit c5b6ba2
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion godot-core/src/obj/onready.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ use std::mem;
/// base: Base<Node>,
/// #[init(node = "ChildPath")]
/// auto: OnReady<Gd<Node2D>>,
/// #[init(default = OnReady::manual())]
/// #[init(val = OnReady::manual())]
/// manual: OnReady<i32>,
/// }
///
Expand Down
6 changes: 3 additions & 3 deletions godot-macros/src/class/derive_godot_class.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ fn parse_fields(
field.default_val = Some(default);
}

// #[init(default = expr)]
// Deprecated #[init(default = expr)]
if let Some(default) = parser.handle_expr("default")? {
if field.default_val.is_some() {
return bail!(
Expand All @@ -454,7 +454,7 @@ fn parse_fields(
parser.span(),
"The key `node` in attribute #[init] requires field of type `OnReady<T>`\n\
Help: The syntax #[init(node = \"NodePath\")] is equivalent to \
#[init(default = OnReady::node(\"NodePath\"))], \
#[init(val = OnReady::node(\"NodePath\"))], \
which can only be assigned to fields of type `OnReady<T>`"
);
}
Expand All @@ -464,7 +464,7 @@ fn parse_fields(
parser.span(),
"The key `node` in attribute #[init] is mutually exclusive with the key `default`\n\
Help: The syntax #[init(node = \"NodePath\")] is equivalent to \
#[init(default = OnReady::node(\"NodePath\"))], \
#[init(val = OnReady::node(\"NodePath\"))], \
both aren't allowed since they would override each other"
);
}
Expand Down
10 changes: 5 additions & 5 deletions godot-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,14 @@ use crate::util::ident;
/// ```
///
/// The generated `init` function will initialize each struct field (except the field of type `Base<T>`, if any)
/// using `Default::default()`. To assign some other value, annotate the field with `#[init(default = ...)]`:
/// using `Default::default()`. To assign some other value, annotate the field with `#[init(val = ...)]`:
///
/// ```
/// # use godot_macros::GodotClass;
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct MyStruct {
/// #[init(default = 42)]
/// #[init(val = 42)]
/// my_field: i64
/// }
/// ```
Expand All @@ -91,7 +91,7 @@ use crate::util::ident;
/// # #[derive(GodotClass)]
/// # #[class(init)]
/// # struct MyStruct {
/// #[init(default = (HashMap::<i64, i64>::new()))]
/// #[init(val = (HashMap::<i64, i64>::new()))]
/// // ^ parentheses needed due to this comma
/// my_field: HashMap<i64, i64>,
/// # }
Expand Down Expand Up @@ -544,7 +544,7 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
///
/// ## Generated `init`
///
/// This initializes the `Base<T>` field, and every other field with either `Default::default()` or the value specified in `#[init(default = ...)]`.
/// This initializes the `Base<T>` field, and every other field with either `Default::default()` or the value specified in `#[init(val = ...)]`.
///
/// ```no_run
/// # use godot::prelude::*;
Expand All @@ -553,7 +553,7 @@ pub fn derive_godot_class(input: TokenStream) -> TokenStream {
/// pub struct MyNode {
/// base: Base<Node>,
///
/// #[init(default = 42)]
/// #[init(val = 42)]
/// some_integer: i64,
/// }
/// ```
Expand Down
2 changes: 1 addition & 1 deletion itest/rust/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ fn generate_property_template(inputs: &[Input]) -> PropertyTests {

let initializer = initializer
.as_ref()
.map(|init| quote! { #[init(default = #init)] });
.map(|init| quote! { #[init(val = #init)] });

rust.extend([
quote! {
Expand Down
2 changes: 1 addition & 1 deletion itest/rust/src/object_tests/onready_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ struct InitWithNodeOrBase {
base: Base<Node>,
#[init(node = "child")]
node: OnReady<Gd<Node>>,
#[init(default = OnReady::from_base_fn(|b| b.get_name().to_string()))]
#[init(val = OnReady::from_base_fn(|b| b.get_name().to_string()))]
self_name: OnReady<String>,
}

Expand Down
4 changes: 2 additions & 2 deletions itest/rust/src/register_tests/var_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ struct WithInitDefaults {
default_int: i64,

#[var(get)]
#[init(default = 42)]
#[init(val = 42)]
literal_int: i64,

#[var(get)]
#[init(default = -42)]
#[init(val = -42)]
expr_int: i64,
}

0 comments on commit c5b6ba2

Please sign in to comment.