Skip to content

Commit db6bede

Browse files
committed
Add a where T: Export bound to the array Export impl
Add some compile_fail doctests for `Export`
1 parent 7634fe7 commit db6bede

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

godot-core/src/builtin/collections/array.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,10 @@ impl<T: ArrayElement> Var for Array<T> {
985985
}
986986
}
987987

988-
impl<T: ArrayElement> Export for Array<T> {
988+
impl<T> Export for Array<T>
989+
where
990+
T: ArrayElement + Export,
991+
{
989992
fn export_hint() -> PropertyHintInfo {
990993
// If T == Variant, then we return "Array" builtin type hint.
991994
if Self::has_variant_t() {

godot-core/src/registry/property.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,47 @@ pub trait Export: Var {
6565
}
6666
}
6767

68+
/// This function only exists as a place to add doc-tests for the `Export` trait.
69+
///
70+
/// Test with export of exportable type should succeed:
71+
/// ```no_run
72+
/// use godot::prelude::*;
73+
///
74+
/// #[derive(GodotClass)]
75+
/// #[class(init)]
76+
/// struct Foo {
77+
/// #[export]
78+
/// obj: Option<Gd<Resource>>,
79+
/// #[export]
80+
/// array: Array<Gd<Resource>>,
81+
/// }
82+
/// ```
83+
///
84+
/// Tests with export of non-exportable type should fail:
85+
/// ```compile_fail
86+
/// use godot::prelude::*;
87+
///
88+
/// #[derive(GodotClass)]
89+
/// #[class(init)]
90+
/// struct Foo {
91+
/// #[export]
92+
/// obj: Option<Gd<Object>>,
93+
/// }
94+
/// ```
95+
///
96+
/// ```compile_fail
97+
/// use godot::prelude::*;
98+
///
99+
/// #[derive(GodotClass)]
100+
/// #[class(init)]
101+
/// struct Foo {
102+
/// #[export]
103+
/// array: Array<Gd<Object>>,
104+
/// }
105+
/// ```
106+
#[allow(dead_code)]
107+
fn export_doctests() {}
108+
68109
// ----------------------------------------------------------------------------------------------------------------------------------------------
69110
// Blanket impls for Option<T>
70111

0 commit comments

Comments
 (0)