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: OriginA Rust or Script source code range where the argument has been provided.
data: CellThe actual data of the argument.
Implementations§
Source§impl<T> DynamicArgument<T>
impl<T> DynamicArgument<T>
Sourcepub fn into_argument(self) -> Arg
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>
impl<'a, T: ScriptType> Downcast<'a> for DynamicArgument<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more