GodotImmutable

Trait GodotImmutable 

pub unsafe trait GodotImmutable: Sized + GodotConvert {
    // Provided method
    fn into_runtime_immutable(self) -> Self { ... }
}
Expand description

Implemented for types that can be used as immutable default parameters in #[func] methods.

This trait ensures that default parameter values cannot be mutated by callers, preventing the Python “mutable default argument” problem where a single default value is shared across multiple calls.

Post-processes the default value in some cases, e.g. makes Array<T> read-only via into_read_only().

At the moment, this trait is conservatively implemented for types where immutability can be statically guaranteed. Depending on usage, the API might be expanded in the future to allow defaults whose immutability is only determined at runtime (e.g. untyped arrays/dictionaries where all element types are immutable).

§Safety

Allows to use the implementors in a limited Sync context. Implementing this trait asserts that Self is either:

  • Copy, i.e. each instance is truly independent.
  • Thread-safe in the sense that clone() is thread-safe. Individual clones must not offer a way to mutate the value or cause race conditions.

Provided Methods§

fn into_runtime_immutable(self) -> Self

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

§

impl GodotImmutable for bool

§

impl GodotImmutable for f32

§

impl GodotImmutable for f64

§

impl GodotImmutable for i8

§

impl GodotImmutable for i16

§

impl GodotImmutable for i32

§

impl GodotImmutable for i64

§

impl GodotImmutable for u8

§

impl GodotImmutable for u16

§

impl GodotImmutable for u32

Implementors§