Struct DynamicReturn

Source
#[repr(transparent)]
pub struct DynamicReturn<T> { pub data: Cell, /* private fields */ }
Expand description

A type for a function’s return value that may have a more dynamic casting nature than usual.

The analyzer will assume that the return type belongs to the type family of the T type, but the Script Engine will not automatically upcast the Rust value, allowing the implementation to manually cast the result into a Cell.

#[export]
fn string_or_number(is_string: bool) -> RuntimeResult<DynamicReturn<usize>> {
    match is_string {
        true => Ok(DynamicReturn::new(Cell::give(Origin::nil(), "string")?)),
        false => Ok(DynamicReturn::new(Cell::give(Origin::nil(), 100usize)?)),
    }
}

Fields§

§data: Cell

The underlying return object.

Implementations§

Source§

impl<T> DynamicReturn<T>

Source

pub fn new(data: Cell) -> Self

A constructor that wraps the provided data Cell into a DynamicReturn.

Trait Implementations§

Source§

impl<'a, T: ScriptType> Upcast<'a> for DynamicReturn<T>

Source§

type Output = Cell

A type into which the input type will be upcasted. Read more
Source§

fn upcast(_origin: Origin, this: Self) -> RuntimeResult<Self::Output>

Creates Script data from Rust data. Read more
Source§

fn hint() -> TypeHint

Returns a rough estimation of the Script type (or a set of types) into which the source Rust type could be upcasted. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DynamicReturn<T>

§

impl<T> !RefUnwindSafe for DynamicReturn<T>

§

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

§

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

§

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

§

impl<T> !UnwindSafe for DynamicReturn<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<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, 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.