Skip to main content

DynamicArgument

Struct DynamicArgument 

Source
pub struct DynamicArgument<T> {
    pub origin: Origin,
    pub data: Cell,
    /* private fields */
}
Expand description

A type of a function’s parameter that may have a more dynamic casting nature than usual.

The analyzer will assume that the argument’s type belongs to the type family of the T type, but the Script Engine will not automatically downcast the script’s argument, allowing the implementation to manually cast the argument’s Cell.

#[export]
fn plus_10(mut arg: DynamicArgument<usize>) -> RuntimeResult<usize> {
    let mut arg_ty = arg.data.type_match();

    if arg_ty.belongs_to::<usize>() {
        let arg = <usize>::downcast(arg.origin, Provider::Borrowed(&mut arg.data))?;

        return Ok(arg + 10);
    }

    if arg_ty.is::<str>() {
        let arg = arg.data.borrow_str(arg.origin)?;

        return Ok(arg.len() + 10);
    }

    Err(arg_ty.mismatch(arg.origin))
}

Fields§

§origin: Origin

A Rust or Script source code range where the argument has been provided.

§data: Cell

The actual data of the argument.

Implementations§

Source§

impl<T> DynamicArgument<T>

Source

pub fn into_argument(self) -> Arg

A helper function that converts this instance into an operator’s argument.

Trait Implementations§

Source§

impl<'a, T: ScriptType> Downcast<'a> for DynamicArgument<T>

Source§

fn downcast(origin: Origin, provider: Provider<'a>) -> RuntimeResult<Self>

Transforms Script data into Rust data. Read more
Source§

fn hint() -> TypeHint

Returns a rough estimation of the Script type (or a set of types) from which the target Rust type could be inferred. Read more

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for DynamicArgument<T>

§

impl<T> !UnwindSafe for DynamicArgument<T>

§

impl<T> Freeze for DynamicArgument<T>

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for DynamicArgument<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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.