pub struct ArgList<'a> { /* private fields */ }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>
impl<'a> ArgList<'a>
Sourcepub fn push_arg(&mut self, arg: ArgValue<'a>)
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.
Sourcepub fn push_ref(&mut self, arg: &'a dyn PartialReflect)
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.
Sourcepub fn push_mut(&mut self, arg: &'a mut dyn PartialReflect)
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.
Sourcepub fn push_owned(&mut self, arg: impl PartialReflect)
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.
Sourcepub fn push_boxed(&mut self, arg: Box<dyn PartialReflect>)
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.
Sourcepub fn with_arg(self, arg: ArgValue<'a>) -> Self
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.
Sourcepub fn with_ref(self, arg: &'a dyn PartialReflect) -> Self
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.
Sourcepub fn with_mut(self, arg: &'a mut dyn PartialReflect) -> Self
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.
Sourcepub fn with_owned(self, arg: impl PartialReflect) -> Self
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.
Sourcepub fn with_boxed(self, arg: Box<dyn PartialReflect>) -> Self
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.
Sourcepub fn take_arg(&mut self) -> Result<Arg<'a>, ArgError>
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.
Sourcepub fn take<T: FromArg>(&mut self) -> Result<T::This<'a>, ArgError>
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);Sourcepub fn take_owned<T: Reflect + TypePath>(&mut self) -> Result<T, ArgError>
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);Sourcepub fn take_ref<T: Reflect + TypePath>(&mut self) -> Result<&'a T, ArgError>
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);Sourcepub fn take_mut<T: Reflect + TypePath>(&mut self) -> Result<&'a mut T, ArgError>
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);Sourcepub fn pop_arg(&mut self) -> Result<Arg<'a>, ArgError>
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.
Sourcepub fn pop<T: FromArg>(&mut self) -> Result<T::This<'a>, ArgError>
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);Sourcepub fn pop_owned<T: Reflect + TypePath>(&mut self) -> Result<T, ArgError>
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);Sourcepub fn pop_ref<T: Reflect + TypePath>(&mut self) -> Result<&'a T, ArgError>
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);Sourcepub fn pop_mut<T: Reflect + TypePath>(&mut self) -> Result<&'a mut T, ArgError>
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);Trait Implementations§
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> 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
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.