Skip to content

Commit

Permalink
Add a where T: Export bound to the array Export impl
Browse files Browse the repository at this point in the history
Add some compile_fail doctests for `Export`
  • Loading branch information
lilizoey committed Aug 27, 2024
1 parent 7634fe7 commit 6bedc41
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
5 changes: 4 additions & 1 deletion godot-core/src/builtin/collections/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,10 @@ impl<T: ArrayElement> Var for Array<T> {
}
}

impl<T: ArrayElement> Export for Array<T> {
impl<T: ArrayElement> Export for Array<T>
where
T: Export,
{
fn export_hint() -> PropertyHintInfo {
// If T == Variant, then we return "Array" builtin type hint.
if Self::has_variant_t() {
Expand Down
41 changes: 41 additions & 0 deletions godot-core/src/registry/property.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,47 @@ pub trait Export: Var {
}
}

/// This function only exists as a place to add doc-tests for the `Export` trait.
///
/// Test with export of exportable type should succeed:
/// ```no_run
/// use godot::prelude::*;
///
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Foo {
/// #[export]
/// obj: Option<Gd<Resource>>,
/// #[export]
/// array: Array<Gd<Resource>>,
/// }
/// ```
///
/// Tests with export of non-exportable type should fail:
/// ```compile_fail
/// use godot::prelude::*;
///
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Foo {
/// #[export]
/// obj: Option<Gd<Object>>,
/// }
/// ```
///
/// ```compile_fail
/// use godot::prelude::*;
///
/// #[derive(GodotClass)]
/// #[class(init)]
/// struct Foo {
/// #[export]
/// array: Array<Gd<Object>>,
/// }
/// ```
#[allow(dead_code)]
fn export_doctests() {}

// ----------------------------------------------------------------------------------------------------------------------------------------------
// Blanket impls for Option<T>

Expand Down

0 comments on commit 6bedc41

Please sign in to comment.