pub struct FuncArgs {
pub args: Vec<PyObjectRef>,
pub kwargs: KwArgs,
}Expand description
The FuncArgs struct is one of the most used structs when 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: KwArgsImplementations§
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: &PyObject) -> PyObjectRef
pub fn get_optional_kwarg(&self, key: &str) -> Option<PyObjectRef>
pub fn get_optional_kwarg_with_type( &self, key: &str, ty: &Py<PyType>, 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 = (Wtf8Buf, 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.
Sourcepub fn bind_for<T: FromArgs>(
self,
vm: &VirtualMachine,
callee: impl Into<Callee>,
) -> PyResult<T>
pub fn bind_for<T: FromArgs>( self, vm: &VirtualMachine, callee: impl Into<Callee>, ) -> PyResult<T>
Binds these arguments the way bind does, for a call whose
function a failure can describe.
pub fn check_kwargs_empty( &self, vm: &VirtualMachine, ) -> Option<PyBaseExceptionRef>
Sourcepub fn check_kwargs_empty_for(
&self,
vm: &VirtualMachine,
callee: impl Into<Callee>,
) -> Option<PyBaseExceptionRef>
pub fn check_kwargs_empty_for( &self, vm: &VirtualMachine, callee: impl Into<Callee>, ) -> Option<PyBaseExceptionRef>
The same as check_kwargs_empty, for a call
whose function the message can name.
Trait Implementations§
Source§impl<Name: ArgName> From<KwArgs<PyObjectRef, Name>> for FuncArgs
impl<Name: ArgName> From<KwArgs<PyObjectRef, Name>> for FuncArgs
Source§fn from(kwargs: KwArgs<PyObjectRef, Name>) -> Self
fn from(kwargs: KwArgs<PyObjectRef, Name>) -> Self
Source§impl FromArgs for FuncArgs
impl FromArgs for FuncArgs
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 !RefUnwindSafe for FuncArgs
impl !Send for FuncArgs
impl !Sync for FuncArgs
impl !UnwindSafe for FuncArgs
impl Freeze for FuncArgs
impl Unpin for FuncArgs
impl UnsafeUnpin 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Helper for T
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
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