Struct PhantomVar
pub struct PhantomVar<T>(/* private fields */)
where
T: GodotType + Var;
Expand description
A zero-sized type for creating a property without a backing field, accessible only through custom getter/setter functions.
This must be used in a struct deriving GodotClass
and requires that the field has
an explicit #[var]
attribute with a custom getter,
and optionally a custom setter. Both getter and setter operate on the specified type T
.
(Note that write-only properties, with a setter but not a getter, are not currently supported. Godot doesn’t fully support them either, silently returning null instead of an error if the property is being read.)
§Example
Suppose you have a field text
whose value you want to keep as a Rust String
rather than a Godot GString
,
accepting the performance penalty for conversions whenever the property is accessed from Godot:
#[derive(GodotClass)]
#[class(init)]
struct Banner {
#[var(get = get_text, set = set_text)]
text: PhantomVar<GString>,
text_string: String,
}
#[godot_api]
impl Banner {
#[func]
fn get_text(&self) -> GString {
GString::from(&self.text_string)
}
#[func]
fn set_text(&mut self, text: GString) {
self.text_string = String::from(&text);
}
}
This field can now be accessed from GDScript as banner.text
.
Trait Implementations§
§impl<T> Clone for PhantomVar<T>
impl<T> Clone for PhantomVar<T>
§fn clone(&self) -> PhantomVar<T>
fn clone(&self) -> PhantomVar<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read more§impl<T> Debug for PhantomVar<T>
impl<T> Debug for PhantomVar<T>
§impl<T> Default for PhantomVar<T>
impl<T> Default for PhantomVar<T>
§fn default() -> PhantomVar<T>
fn default() -> PhantomVar<T>
§impl<T> Export for PhantomVar<T>
impl<T> Export for PhantomVar<T>
§fn export_hint() -> PropertyHintInfo
fn export_hint() -> PropertyHintInfo
§impl<T> GodotConvert for PhantomVar<T>
impl<T> GodotConvert for PhantomVar<T>
§impl<T> Hash for PhantomVar<T>
impl<T> Hash for PhantomVar<T>
§impl<T> Ord for PhantomVar<T>
impl<T> Ord for PhantomVar<T>
§impl<T> PartialEq for PhantomVar<T>
impl<T> PartialEq for PhantomVar<T>
§impl<T> PartialOrd for PhantomVar<T>
impl<T> PartialOrd for PhantomVar<T>
§impl<T> Var for PhantomVar<T>
impl<T> Var for PhantomVar<T>
fn get_property(&self) -> <PhantomVar<T> as GodotConvert>::Via
fn set_property(&mut self, _value: <PhantomVar<T> as GodotConvert>::Via)
§fn var_hint() -> PropertyHintInfo
fn var_hint() -> PropertyHintInfo
GodotType::property_info
, e.g. for enums/newtypes.