Skip to content

Commit 1c95175

Browse files
committed
(trait expment)
1 parent 2eaa443 commit 1c95175

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

godot-core/src/meta/traits.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use godot_ffi as sys;
99

10-
use crate::builtin;
1110
use crate::builtin::{Variant, VariantType};
1211
use crate::global::PropertyUsageFlags;
1312
use crate::meta::error::ConvertError;
@@ -16,6 +15,7 @@ use crate::meta::{
1615
};
1716
use crate::registry::method::MethodParamOrReturnInfo;
1817
use crate::registry::property::builtin_type_string;
18+
use crate::{builtin, meta};
1919

2020
// Re-export sys traits in this module, so all are in one place.
2121
#[rustfmt::skip] // Do not reorder.
@@ -213,6 +213,25 @@ pub trait ArrayElement: ToGodot + FromGodot + sealed::Sealed + 'static {
213213
}
214214
}
215215

216+
pub trait ElementLiteral {
217+
type Element;
218+
fn to_element(&self) -> Self::Element;
219+
}
220+
221+
impl<T> ElementLiteral for T
222+
where
223+
T: ToGodot<Pass = meta::ByValue> + Copy,
224+
{
225+
type Element = T;
226+
fn to_element(&self) -> Self::Element {
227+
*self
228+
}
229+
}
230+
231+
pub fn elem<T: ElementLiteral>(element: &T) -> T::Element {
232+
element.to_element()
233+
}
234+
216235
// ----------------------------------------------------------------------------------------------------------------------------------------------
217236
// Non-polymorphic helper functions, to avoid constant `<T::Via as GodotType>::` in the code.
218237

0 commit comments

Comments
 (0)