Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make arrays exportable only when their inner type is exportable #875

Merged
merged 1 commit into from
Sep 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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> Export for Array<T>
where
T: ArrayElement + 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
Loading