Struct DynamicType

Source
pub struct DynamicType;
Expand description

A type that cannot be inferred during static semantic analysis.

Normally, you should not instantiate or use this object in implementations, but you can use this type as a hint for the analyzer when the implementation nature is fully dynamic.

struct Foo;

#[export]
type FooAlias = Foo;

#[export]
impl ScriptAssign for Foo {
    // `type RHS = Foo;` would be more preferable in this case.
    type RHS = DynamicType;

    fn script_assign(_origin: Origin, lhs: Arg, rhs: Arg) -> RuntimeResult<()> {
        let rhs = rhs.data.take::<Foo>(rhs.origin)?;

        let (lhs_origin, mut lhs_cell) = lhs.split();

        let lhs = lhs_cell.borrow_mut::<Foo>(lhs_origin)?;

        *lhs = rhs;

        Ok(())
    }
}

Generally, it is recommended to use this type as sparingly as possible, preferring more specific types even if they provide an imprecise description.

If you need more control over the exported function’s arguments and result type casting, consider using DynamicArgument and DynamicReturn wrappers instead.

Auto Trait Implementations§

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> 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> ScriptType for T
where T: RegisteredType + ?Sized,

Source§

fn type_meta() -> &'static TypeMeta

Returns the introspection metadata of this Rust type registered in the Script Engine.
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.