Enum rustpython_vm::function::OptionalArg
source · 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>
type Inner = T
fn from_inner(x: T) -> Self
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> 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