pub enum OptionalArg<T = PyObjectRef> {
Present(T),
Missing,
}
Expand description
An argument that may or may not be provided by the caller.
This style of argument is not possible in pure Python.
Variants§
Implementations§
Source§impl<T> OptionalArg<T>
impl<T> OptionalArg<T>
pub fn from_option(option: Option<T>) -> Self
pub fn into_option(self) -> Option<T>
pub fn as_option(&self) -> Option<&T>
pub fn as_option_mut(&mut self) -> Option<&mut T>
pub fn expect(self, msg: &str) -> T
pub fn unwrap(self) -> T
pub fn unwrap_or(self, default: T) -> T
pub fn unwrap_or_else<_Function: FnOnce() -> T>(self, f: _Function) -> T
pub fn ok_or<_Error>(self, err: _Error) -> Result<T, _Error>
pub fn ok_or_else<_Error, _Function: FnOnce() -> _Error>( self, err: _Function, ) -> Result<T, _Error>
pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self
pub fn or(self, optb: Self) -> Self
pub fn or_else<_Function: FnOnce() -> Self>(self, f: _Function) -> Self
pub fn map_or<_Other, _Function: FnOnce(T) -> _Other>( self, default: _Other, f: _Function, ) -> _Other
pub fn xor(self, optb: Self) -> Self
pub fn get_or_insert(&mut self, v: T) -> &mut T
pub fn get_or_insert_with<_Function: FnOnce() -> T>( &mut self, f: _Function, ) -> &mut T
pub fn replace(&mut self, value: T) -> Self
Source§impl<T> OptionalArg<T>
impl<T> OptionalArg<T>
pub fn as_ref(&self) -> OptionalArg<&T>
pub fn as_mut(&mut self) -> OptionalArg<&mut T>
pub fn map<_Other, _Function: FnOnce(T) -> _Other>( self, f: _Function, ) -> OptionalArg<_Other>
pub fn map_or_else<_Other, _Default: FnOnce() -> _Other, _Function: FnOnce(T) -> _Other>( self, default: _Default, f: _Function, ) -> _Other
pub fn iter(&self) -> impl Iterator<Item = &T>
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>
pub fn and<_Other>(self, optb: OptionalArg<_Other>) -> OptionalArg<_Other>
pub fn and_then<_Other, _Function: FnOnce(T) -> OptionalArg<_Other>>( self, f: _Function, ) -> OptionalArg<_Other>
pub fn zip<_Other>(self, other: OptionalArg<_Other>) -> OptionalArg<(T, _Other)>
pub fn take(&mut self) -> Selfwhere
T: Default,
pub fn unwrap_or_default(self) -> Twhere
T: Default,
Source§impl<T> OptionalArg<&T>where
T: Copy,
impl<T> OptionalArg<&T>where
T: Copy,
pub fn copied(self) -> OptionalArg<T>
Source§impl<T> OptionalArg<&mut T>where
T: Copy,
impl<T> OptionalArg<&mut T>where
T: Copy,
pub fn copied(self) -> OptionalArg<T>
Source§impl<T> OptionalArg<&T>where
T: Clone,
impl<T> OptionalArg<&T>where
T: Clone,
pub fn cloned(self) -> OptionalArg<T>
Source§impl<T> OptionalArg<&mut T>where
T: Clone,
impl<T> OptionalArg<&mut T>where
T: Clone,
pub fn cloned(self) -> OptionalArg<T>
Source§impl<T> OptionalArg<T>where
T: Deref,
impl<T> OptionalArg<T>where
T: Deref,
pub fn as_deref(&self) -> OptionalArg<&T::Target>
Source§impl<T: DerefMut> OptionalArg<T>
impl<T: DerefMut> OptionalArg<T>
pub fn as_deref_mut(&mut self) -> OptionalArg<&mut T::Target>
Source§impl<T, _Error> OptionalArg<Result<T, _Error>>
impl<T, _Error> OptionalArg<Result<T, _Error>>
pub fn transpose(self) -> Result<OptionalArg<T>, _Error>
Source§impl<T> OptionalArg<T>
impl<T> OptionalArg<T>
Sourcepub const fn is_present(&self) -> bool
pub const fn is_present(&self) -> bool
Returns true
if self
is of variant Present
.
Sourcepub fn as_present(&self) -> Option<&T>
pub fn as_present(&self) -> Option<&T>
Returns Some
if self
is a reference of variant Present
, and None
otherwise.
Sourcepub fn as_mut_present(&mut self) -> Option<&mut T>
pub fn as_mut_present(&mut self) -> Option<&mut T>
Returns Some
if self
is a mutable reference of variant Present
, and None
otherwise.
Sourcepub fn expect_present(self) -> Twhere
Self: Debug,
pub fn expect_present(self) -> Twhere
Self: Debug,
Sourcepub fn present(self) -> Option<T>
pub fn present(self) -> Option<T>
Returns Some
if self
is of variant Present
, and None
otherwise.
Sourcepub const fn is_missing(&self) -> bool
pub const fn is_missing(&self) -> bool
Returns true
if self
is of variant Missing
.
Source§impl OptionalArg<PyObjectRef>
impl OptionalArg<PyObjectRef>
pub fn unwrap_or_none(self, vm: &VirtualMachine) -> PyObjectRef
Source§impl<T> OptionalArg<ArgPrimitiveIndex<T>>
impl<T> OptionalArg<ArgPrimitiveIndex<T>>
pub fn into_primitive(self) -> OptionalArg<T>
Trait Implementations§
Source§impl<T> Clone for OptionalArg<T>where
T: Clone,
impl<T> Clone for OptionalArg<T>where
T: Clone,
Source§impl<T: Debug> Debug for OptionalArg<T>
impl<T: Debug> Debug for OptionalArg<T>
Source§impl<T> Default for OptionalArg<T>
impl<T> Default for OptionalArg<T>
Source§impl<T> From<Option<T>> for OptionalArg<T>
impl<T> From<Option<T>> for OptionalArg<T>
Source§impl<T> From<OptionalArg<T>> for Option<T>
impl<T> From<OptionalArg<T>> for Option<T>
Source§fn from(value: OptionalArg<T>) -> Self
fn from(value: OptionalArg<T>) -> Self
Converts to this type from the input type.
Source§impl<T> From<T> for OptionalArg<T>
impl<T> From<T> for OptionalArg<T>
Source§impl<T: TryFromObject> FromArgOptional for OptionalArg<T>
impl<T: TryFromObject> FromArgOptional for OptionalArg<T>
Source§impl<T> FromArgs for OptionalArg<T>where
T: TryFromObject,
impl<T> FromArgs for OptionalArg<T>where
T: TryFromObject,
Source§fn arity() -> RangeInclusive<usize>
fn arity() -> RangeInclusive<usize>
The range of positional arguments permitted by the function signature. Read more
Source§fn from_args(
vm: &VirtualMachine,
args: &mut FuncArgs,
) -> Result<Self, ArgumentError>
fn from_args( vm: &VirtualMachine, args: &mut FuncArgs, ) -> Result<Self, ArgumentError>
Extracts this item from the next argument(s).
Source§impl<T> IntoIterator for OptionalArg<T>
impl<T> IntoIterator for OptionalArg<T>
Source§impl<T> OptionLike for OptionalArg<T>
impl<T> OptionLike for OptionalArg<T>
Source§impl<T> Traverse for OptionalArg<T>where
T: Traverse,
impl<T> Traverse for OptionalArg<T>where
T: Traverse,
Source§fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
impl
traverse()
with caution! Following those guideline so traverse doesn’t cause memory error!: Read moreimpl<T> Copy for OptionalArg<T>where
T: Copy,
Auto Trait Implementations§
impl<T> Freeze for OptionalArg<T>where
T: Freeze,
impl<T> RefUnwindSafe for OptionalArg<T>where
T: RefUnwindSafe,
impl<T> Send for OptionalArg<T>where
T: Send,
impl<T> Sync for OptionalArg<T>where
T: Sync,
impl<T> Unpin for OptionalArg<T>where
T: Unpin,
impl<T> UnwindSafe for OptionalArg<T>where
T: UnwindSafe,
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
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>
Converts
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>
Converts
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