Skip to content

Commit ab08cd2

Browse files
authored
Merge pull request #1079 from ColinWttt/patch-1
Rename: OnEditor `invalid` to `sentinel`
2 parents d4fb159 + 261f6ac commit ab08cd2

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

godot-core/src/obj/oneditor.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ use crate::registry::property::{BuiltinExport, Export, Var};
114114
/// `OnEditor<T>` can be used with other built-ins to provide extra validation logic and making sure that given properties has been set.
115115
/// Example usage might be checking if entities has been granted properly generated id.
116116
///
117-
/// In such cases the value which will be deemed invalid **must** be specified with `#[init(uninit = val)]`.
117+
/// In such cases the value which will be deemed invalid **must** be specified with `#[init(sentinel = val)]`.
118118
/// Given `val` will be used to represent uninitialized `OnEditor<T>` in the Godot editor.
119119
/// Accessing uninitialized value will cause the panic.
120120
///
@@ -129,7 +129,7 @@ use crate::registry::property::{BuiltinExport, Export, Var};
129129
/// // Uninitialized value will be represented by `42` in the editor.
130130
/// // Will cause panic if not set via the editor or code before use.
131131
/// #[export]
132-
/// #[init(invalid = 42)]
132+
/// #[init(sentinel = 42)]
133133
/// some_primitive: OnEditor<i64>,
134134
/// }
135135
///
@@ -190,7 +190,7 @@ impl<T: Var + FromGodot + PartialEq> OnEditor<T> {
190190
/// Creates new `OnEditor<T>` with a value that is considered invalid.
191191
///
192192
/// If this value is not changed in the editor, accessing it from Rust will cause a panic.
193-
pub fn new_invalid(val: T) -> Self
193+
pub fn from_sentinel(val: T) -> Self
194194
where
195195
T::Via: BuiltinExport,
196196
{

godot-macros/src/class/derive_godot_class.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -592,27 +592,27 @@ fn parse_fields(
592592
});
593593
}
594594

595-
// #[init(invalid = val)]
596-
if let Some(invalid_representation) = parser.handle_expr("invalid")? {
595+
// #[init(sentinel = val)]
596+
if let Some(sentinel_representation) = parser.handle_expr("sentinel")? {
597597
let mut is_well_formed = true;
598598
if !field.is_oneditor {
599599
is_well_formed = false;
600600
errors.push(error!(
601601
parser.span(),
602-
"The key `invalid` in attribute #[init] requires field of type `OnEditor<T>`"
602+
"The key `sentinel` in attribute #[init] requires field of type `OnEditor<T>`"
603603
));
604604
}
605605

606606
if field.default_val.is_some() {
607607
is_well_formed = false;
608608
errors.push(error!(
609609
parser.span(),
610-
"The key `invalid` in attribute #[init] is mutually exclusive with the keys `default` and `val`"
610+
"The key `sentinel` in attribute #[init] is mutually exclusive with the keys `default` and `val`"
611611
));
612612
}
613613

614614
let default_val = if is_well_formed {
615-
quote! { OnEditor::new_invalid( #invalid_representation ) }
615+
quote! { OnEditor::from_sentinel( #sentinel_representation ) }
616616
} else {
617617
quote! { todo!() }
618618
};

itest/rust/src/object_tests/oneditor_test.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use godot::obj::{Gd, NewAlloc, OnEditor};
1414

1515
#[itest]
1616
fn oneditor_deref() {
17-
let mut on_editor = OnEditor::new_invalid(0);
17+
let mut on_editor = OnEditor::from_sentinel(0);
1818
on_editor.init(42);
1919
assert_eq!(*on_editor, 42);
2020

@@ -25,7 +25,7 @@ fn oneditor_deref() {
2525
#[itest]
2626
fn oneditor_no_value_panic_on_deref_primitive() {
2727
expect_panic("Deref on null fails for primitive", || {
28-
let on_editor_panic: OnEditor<i64> = OnEditor::new_invalid(0);
28+
let on_editor_panic: OnEditor<i64> = OnEditor::from_sentinel(0);
2929
let _ref: &i64 = &on_editor_panic;
3030
});
3131
expect_panic("Deref on null fails for Gd class", || {
@@ -34,7 +34,7 @@ fn oneditor_no_value_panic_on_deref_primitive() {
3434
});
3535

3636
expect_panic("DerefMut on null fails for primitive", || {
37-
let mut on_editor_panic: OnEditor<i64> = OnEditor::new_invalid(0);
37+
let mut on_editor_panic: OnEditor<i64> = OnEditor::from_sentinel(0);
3838
let _ref: &mut i64 = &mut on_editor_panic;
3939
});
4040
expect_panic("DerefMut on null fails for Gd class", || {
@@ -68,7 +68,7 @@ fn oneditor_no_panic_on_ready() {
6868
#[class(init, base=Node)]
6969
struct OnEditorNoDefault {
7070
#[export]
71-
#[init(invalid = 0)]
71+
#[init(sentinel = 0)]
7272
some_primitive: OnEditor<i64>,
7373
#[export]
7474
node_field: OnEditor<Gd<Node>>,

0 commit comments

Comments
 (0)