Struct Unique
pub struct Unique<T>where
T: UniqueType,{ /* private fields */ }Expand description
Makes sure the inner value is unique and can be safely shared across threads.
No other part of the engine will have access to the inner value and only Send + Sync or other Unique<T> values can be passed to
functions on T. Unique also blocks access to Gd::clone or to their InstanceId.
Unique supports these generally not thread safe types:
Implementations§
§impl<K, V> Unique<Dictionary<K, V>>
impl<K, V> Unique<Dictionary<K, V>>
pub fn new() -> Unique<Dictionary<K, V>>
§impl<T> Unique<Gd<T>>
impl<T> Unique<Gd<T>>
pub fn try_from_ref_counted(value: Gd<T>) -> Option<Unique<Gd<T>>>
Available on since_api=4.4 only.
pub fn try_from_ref_counted(value: Gd<T>) -> Option<Unique<Gd<T>>>
since_api=4.4 only.Attempts to verify that the provided ref-counted object is in fact unique.
This might fail if the object is referenced by anything else or any of its internal references are shared with other objects. Specific reasons for this conversion to fail:
- Object class is user created.
- Object has a script attached.
- Reference counter is > 1.
- Reference count of any property value is > 1.
- Any property value directly inherits from Object (manually managed).
- Any property value is of type Dictionary or any of the Array types.
- Any property is a custom callable.
- Any property fails these checks recursively.
Since all checks are applied recursively to all objects which are referenced by the given value this conversion can potentially be quite expensive.
§impl<T> Unique<Gd<T>>where
T: GodotClass<Declarer = DeclEngine>,
impl<T> Unique<Gd<T>>where
T: GodotClass<Declarer = DeclEngine>,
§impl<T> Unique<Gd<T>>where
T: GodotClass<Declarer = DeclUser>,
impl<T> Unique<Gd<T>>where
T: GodotClass<Declarer = DeclUser>,
§impl<K, V> Unique<Dictionary<K, V>>
impl<K, V> Unique<Dictionary<K, V>>
pub fn apply<F>(&mut self, f: F)
pub fn apply<F>(&mut self, f: F)
Apply modifications to unique instance of the inner type.
All captured outer variables must be thread-safe.
pub fn upcast_any_dictionary(self) -> Unique<AnyDictionary>
pub fn upcast_any_dictionary(self) -> Unique<AnyDictionary>
Downgrades this typed/untyped Unique<Dictionary<T>> into a Unique<AnyArray>.
This method is useful if you need AnyArray instead of a typed one.
§impl<V> Unique<Array<V>>where
V: Element,
impl<V> Unique<Array<V>>where
V: Element,
pub fn apply<F>(&mut self, f: F)
pub fn apply<F>(&mut self, f: F)
Apply modifications to unique instance of the inner type.
All captured outer variables must be thread-safe.
pub fn upcast_any_array(self) -> Unique<AnyArray>
pub fn upcast_any_array(self) -> Unique<AnyArray>
Downgrades this typed/untyped Unique<Array<T>> into a Unique<AnyArray>.
This method is useful if you need AnyArray instead of a typed one.
§impl<T> Unique<T>where
T: UniqueType,
impl<T> Unique<T>where
T: UniqueType,
Unwraps the inner value and gives up all uniqueness guarantees.