ArgList

Struct ArgList 

Source
pub struct ArgList<'a> { /* private fields */ }
Available on crate feature functions only.
Expand description

A list of arguments that can be passed to a DynamicFunction or DynamicFunctionMut.

§Example

let foo = 123;
let bar = 456;
let mut baz = 789;
let args = ArgList::new()
  // Push an owned argument
  .with_owned(foo)
  // Push an owned and boxed argument
  .with_boxed(Box::new(foo))
  // Push a reference argument
  .with_ref(&bar)
  // Push a mutable reference argument
  .with_mut(&mut baz)
  // Push a manually constructed argument
  .with_arg(ArgValue::Ref(&3.14));

Implementations§

Source§

impl<'a> ArgList<'a>

Source

pub fn new() -> Self

Create a new empty list of arguments.

Source

pub fn push_arg(&mut self, arg: ArgValue<'a>)

Push an ArgValue onto the list.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn push_ref(&mut self, arg: &'a dyn PartialReflect)

Push an ArgValue::Ref onto the list with the given reference.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn push_mut(&mut self, arg: &'a mut dyn PartialReflect)

Push an ArgValue::Mut onto the list with the given mutable reference.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn push_owned(&mut self, arg: impl PartialReflect)

Push an ArgValue::Owned onto the list with the given owned value.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn push_boxed(&mut self, arg: Box<dyn PartialReflect>)

Push an ArgValue::Owned onto the list with the given boxed value.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn with_arg(self, arg: ArgValue<'a>) -> Self

Push an ArgValue onto the list.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn with_ref(self, arg: &'a dyn PartialReflect) -> Self

Push an ArgValue::Ref onto the list with the given reference.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn with_mut(self, arg: &'a mut dyn PartialReflect) -> Self

Push an ArgValue::Mut onto the list with the given mutable reference.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn with_owned(self, arg: impl PartialReflect) -> Self

Push an ArgValue::Owned onto the list with the given owned value.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn with_boxed(self, arg: Box<dyn PartialReflect>) -> Self

Push an ArgValue::Owned onto the list with the given boxed value.

If an argument was previously removed from the beginning of the list, this method will also re-index the list.

Source

pub fn take_arg(&mut self) -> Result<Arg<'a>, ArgError>

Remove the first argument in the list and return it.

It’s generally preferred to use Self::take instead of this method as it provides a more ergonomic way to immediately downcast the argument.

Source

pub fn take<T: FromArg>(&mut self) -> Result<T::This<'a>, ArgError>

Remove the first argument in the list and return Ok(T::This).

If the list is empty or the FromArg::from_arg call fails, returns an error.

§Example
let a = 1u32;
let b = 2u32;
let mut c = 3u32;
let mut args = ArgList::new().with_owned(a).with_ref(&b).with_mut(&mut c);

let a = args.take::<u32>().unwrap();
assert_eq!(a, 1);

let b = args.take::<&u32>().unwrap();
assert_eq!(*b, 2);

let c = args.take::<&mut u32>().unwrap();
assert_eq!(*c, 3);
Source

pub fn take_owned<T: Reflect + TypePath>(&mut self) -> Result<T, ArgError>

Remove the first argument in the list and return Ok(T) if the argument is ArgValue::Owned.

If the list is empty or the argument is not owned, returns an error.

It’s generally preferred to use Self::take instead of this method.

§Example
let value = 123u32;
let mut args = ArgList::new().with_owned(value);
let value = args.take_owned::<u32>().unwrap();
assert_eq!(value, 123);
Source

pub fn take_ref<T: Reflect + TypePath>(&mut self) -> Result<&'a T, ArgError>

Remove the first argument in the list and return Ok(&T) if the argument is ArgValue::Ref.

If the list is empty or the argument is not a reference, returns an error.

It’s generally preferred to use Self::take instead of this method.

§Example
let value = 123u32;
let mut args = ArgList::new().with_ref(&value);
let value = args.take_ref::<u32>().unwrap();
assert_eq!(*value, 123);
Source

pub fn take_mut<T: Reflect + TypePath>(&mut self) -> Result<&'a mut T, ArgError>

Remove the first argument in the list and return Ok(&mut T) if the argument is ArgValue::Mut.

If the list is empty or the argument is not a mutable reference, returns an error.

It’s generally preferred to use Self::take instead of this method.

§Example
let mut value = 123u32;
let mut args = ArgList::new().with_mut(&mut value);
let value = args.take_mut::<u32>().unwrap();
assert_eq!(*value, 123);
Source

pub fn pop_arg(&mut self) -> Result<Arg<'a>, ArgError>

Remove the last argument in the list and return it.

It’s generally preferred to use Self::pop instead of this method as it provides a more ergonomic way to immediately downcast the argument.

Source

pub fn pop<T: FromArg>(&mut self) -> Result<T::This<'a>, ArgError>

Remove the last argument in the list and return Ok(T::This).

If the list is empty or the FromArg::from_arg call fails, returns an error.

§Example
let a = 1u32;
let b = 2u32;
let mut c = 3u32;
let mut args = ArgList::new().with_owned(a).with_ref(&b).with_mut(&mut c);

let c = args.pop::<&mut u32>().unwrap();
assert_eq!(*c, 3);

let b = args.pop::<&u32>().unwrap();
assert_eq!(*b, 2);

let a = args.pop::<u32>().unwrap();
assert_eq!(a, 1);
Source

pub fn pop_owned<T: Reflect + TypePath>(&mut self) -> Result<T, ArgError>

Remove the last argument in the list and return Ok(T) if the argument is ArgValue::Owned.

If the list is empty or the argument is not owned, returns an error.

It’s generally preferred to use Self::pop instead of this method.

§Example
let value = 123u32;
let mut args = ArgList::new().with_owned(value);
let value = args.pop_owned::<u32>().unwrap();
assert_eq!(value, 123);
Source

pub fn pop_ref<T: Reflect + TypePath>(&mut self) -> Result<&'a T, ArgError>

Remove the last argument in the list and return Ok(&T) if the argument is ArgValue::Ref.

If the list is empty or the argument is not a reference, returns an error.

It’s generally preferred to use Self::pop instead of this method.

§Example
let value = 123u32;
let mut args = ArgList::new().with_ref(&value);
let value = args.pop_ref::<u32>().unwrap();
assert_eq!(*value, 123);
Source

pub fn pop_mut<T: Reflect + TypePath>(&mut self) -> Result<&'a mut T, ArgError>

Remove the last argument in the list and return Ok(&mut T) if the argument is ArgValue::Mut.

If the list is empty or the argument is not a mutable reference, returns an error.

It’s generally preferred to use Self::pop instead of this method.

§Example
let mut value = 123u32;
let mut args = ArgList::new().with_mut(&mut value);
let value = args.pop_mut::<u32>().unwrap();
assert_eq!(*value, 123);
Source

pub fn iter(&self) -> Iter<'_, Arg<'a>>

Returns an iterator over the arguments in the list.

Source

pub fn len(&self) -> usize

Returns the number of arguments in the list.

Source

pub fn is_empty(&self) -> bool

Returns true if the list of arguments is empty.

Trait Implementations§

Source§

impl<'a> Debug for ArgList<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Default for ArgList<'a>

Source§

fn default() -> ArgList<'a>

Returns the “default value” for a type. Read more
Source§

impl From<&ArgList<'_>> for ArgumentSignature

Source§

fn from(args: &ArgList<'_>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> Freeze for ArgList<'a>

§

impl<'a> !RefUnwindSafe for ArgList<'a>

§

impl<'a> Send for ArgList<'a>

§

impl<'a> Sync for ArgList<'a>

§

impl<'a> Unpin for ArgList<'a>

§

impl<'a> !UnwindSafe for ArgList<'a>

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> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
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<A> Is for A
where A: Any,

Source§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
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.
Source§

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

Source§

impl<T> WasmNotSendSync for T

Source§

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