PhantomVar

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>
where T: GodotType + Var,

§

fn clone(&self) -> PhantomVar<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T> Debug for PhantomVar<T>
where T: GodotType + Var,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T> Default for PhantomVar<T>
where T: GodotType + Var,

§

fn default() -> PhantomVar<T>

Returns the “default value” for a type. Read more
§

impl<T> Export for PhantomVar<T>
where T: GodotType + Var + Export,

§

fn export_hint() -> PropertyHintInfo

The export info to use for an exported field of this type, if no other export info is specified.
§

impl<T> GodotConvert for PhantomVar<T>
where T: GodotType + Var,

§

type Via = T

The type through which Self is represented in Godot.
§

impl<T> Hash for PhantomVar<T>
where T: GodotType + Var,

§

fn hash<H>(&self, _state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<T> Ord for PhantomVar<T>
where T: GodotType + Var,

§

fn cmp(&self, _other: &PhantomVar<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
§

impl<T> PartialEq for PhantomVar<T>
where T: GodotType + Var,

§

fn eq(&self, _other: &PhantomVar<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<T> PartialOrd for PhantomVar<T>
where T: GodotType + Var,

§

fn partial_cmp(&self, other: &PhantomVar<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
§

impl<T> Var for PhantomVar<T>
where T: GodotType + Var,

§

fn get_property(&self) -> <PhantomVar<T> as GodotConvert>::Via

§

fn set_property(&mut self, _value: <PhantomVar<T> as GodotConvert>::Via)

§

fn var_hint() -> PropertyHintInfo

Specific property hints, only override if they deviate from GodotType::property_info, e.g. for enums/newtypes.
§

impl<T> Copy for PhantomVar<T>
where T: GodotType + Var,

§

impl<T> Eq for PhantomVar<T>
where T: GodotType + Var,

Auto Trait Implementations§

§

impl<T> Freeze for PhantomVar<T>

§

impl<T> RefUnwindSafe for PhantomVar<T>
where T: RefUnwindSafe,

§

impl<T> Send for PhantomVar<T>
where T: Send,

§

impl<T> Sync for PhantomVar<T>
where T: Sync,

§

impl<T> Unpin for PhantomVar<T>
where T: Unpin,

§

impl<T> UnwindSafe for PhantomVar<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.