pub struct FuncArgs {
pub args: Vec<PyObjectRef>,
pub kwargs: IndexMap<String, PyObjectRef>,
}Expand description
The FuncArgs struct is one of the most used structs then creating
a rust function that can be called from python. It holds both positional
arguments, as well as keyword arguments passed to the function.
Fields§
§args: Vec<PyObjectRef>§kwargs: IndexMap<String, PyObjectRef>Implementations§
Source§impl FuncArgs
impl FuncArgs
pub fn new<A, K>(args: A, kwargs: K) -> Self
pub fn with_kwargs_names<A, KW>(args: A, kwarg_names: KW) -> Self
Sourcepub fn from_vectorcall(
args: &[PyObjectRef],
nargs: usize,
kwnames: Option<&[PyObjectRef]>,
) -> Self
pub fn from_vectorcall( args: &[PyObjectRef], nargs: usize, kwnames: Option<&[PyObjectRef]>, ) -> Self
Create FuncArgs from a vectorcall-style argument slice (PEP 590).
args[..nargs] are positional, and if kwnames is provided,
the last kwnames.len() entries in args[nargs..] are keyword values.
Convert borrowed vectorcall args to FuncArgs (clones all values).
Sourcepub fn from_vectorcall_owned(
args: Vec<PyObjectRef>,
nargs: usize,
kwnames: Option<&[PyObjectRef]>,
) -> Self
pub fn from_vectorcall_owned( args: Vec<PyObjectRef>, nargs: usize, kwnames: Option<&[PyObjectRef]>, ) -> Self
Convert owned vectorcall args to FuncArgs (moves values, no clone).
pub fn is_empty(&self) -> bool
pub fn prepend_arg(&mut self, item: PyObjectRef)
pub fn shift(&mut self) -> PyObjectRef
pub fn get_kwarg(&self, key: &str, default: PyObjectRef) -> PyObjectRef
pub fn get_optional_kwarg(&self, key: &str) -> Option<PyObjectRef>
pub fn get_optional_kwarg_with_type( &self, key: &str, ty: PyTypeRef, vm: &VirtualMachine, ) -> PyResult<Option<PyObjectRef>>
pub fn take_positional(&mut self) -> Option<PyObjectRef>
pub fn take_positional_keyword(&mut self, name: &str) -> Option<PyObjectRef>
pub fn take_keyword(&mut self, name: &str) -> Option<PyObjectRef>
pub fn remaining_keywords( &mut self, ) -> impl Iterator<Item = (String, PyObjectRef)> + '_
Sourcepub fn bind<T: FromArgs>(self, vm: &VirtualMachine) -> PyResult<T>
pub fn bind<T: FromArgs>(self, vm: &VirtualMachine) -> PyResult<T>
Binds these arguments to their respective values.
If there is an insufficient number of arguments, there are leftover arguments after performing the binding, or if an argument is not of the expected type, a TypeError is raised.
If the given FromArgs includes any conversions, exceptions raised
during the conversion will halt the binding and return the error.
pub fn check_kwargs_empty( &self, vm: &VirtualMachine, ) -> Option<PyBaseExceptionRef>
Trait Implementations§
Source§impl FromArgs for FuncArgs
impl FromArgs for FuncArgs
Source§fn from_args(
_vm: &VirtualMachine,
args: &mut FuncArgs,
) -> Result<Self, ArgumentError>
fn from_args( _vm: &VirtualMachine, args: &mut FuncArgs, ) -> Result<Self, ArgumentError>
Source§impl Traverse for FuncArgs
impl Traverse for FuncArgs
Source§fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
traverse() with caution! Following those guideline so traverse doesn’t cause memory error!: Read moreSource§fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
Auto Trait Implementations§
impl Freeze for FuncArgs
impl !RefUnwindSafe for FuncArgs
impl !Send for FuncArgs
impl !Sync for FuncArgs
impl Unpin for FuncArgs
impl UnsafeUnpin for FuncArgs
impl !UnwindSafe for FuncArgs
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more