Skip to main content

OptionalArg

Enum 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§

§

Present(T)

§

Missing

Implementations§

Source§

impl<T> OptionalArg<T>

Source

pub fn from_option(option: Option<T>) -> Self

Source

pub fn into_option(self) -> Option<T>

Source

pub fn as_option(&self) -> Option<&T>

Source

pub fn as_option_mut(&mut self) -> Option<&mut T>

Source

pub fn expect(self, msg: &str) -> T

Source

pub fn unwrap(self) -> T

Source

pub fn unwrap_or(self, default: T) -> T

Source

pub fn unwrap_or_else<_Function: FnOnce() -> T>(self, f: _Function) -> T

Source

pub fn ok_or<_Error>(self, err: _Error) -> Result<T, _Error>

Source

pub fn ok_or_else<_Error, _Function: FnOnce() -> _Error>( self, err: _Function, ) -> Result<T, _Error>

Source

pub fn filter<P: FnOnce(&T) -> bool>(self, predicate: P) -> Self

Source

pub fn or(self, optb: Self) -> Self

Source

pub fn or_else<_Function: FnOnce() -> Self>(self, f: _Function) -> Self

Source

pub fn map_or<_Other, _Function: FnOnce(T) -> _Other>( self, default: _Other, f: _Function, ) -> _Other

Source

pub fn xor(self, optb: Self) -> Self

Source

pub fn get_or_insert(&mut self, v: T) -> &mut T

Source

pub fn get_or_insert_with<_Function: FnOnce() -> T>( &mut self, f: _Function, ) -> &mut T

Source

pub fn replace(&mut self, value: T) -> Self

Source§

impl<T> OptionalArg<T>

Source

pub fn as_ref(&self) -> OptionalArg<&T>

Source

pub fn as_mut(&mut self) -> OptionalArg<&mut T>

Source

pub fn map<_Other, _Function: FnOnce(T) -> _Other>( self, f: _Function, ) -> OptionalArg<_Other>

Source

pub fn map_or_else<_Other, _Default: FnOnce() -> _Other, _Function: FnOnce(T) -> _Other>( self, default: _Default, f: _Function, ) -> _Other

Source

pub fn iter(&self) -> impl Iterator<Item = &T>

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T>

Source

pub fn and<_Other>(self, optb: OptionalArg<_Other>) -> OptionalArg<_Other>

Source

pub fn and_then<_Other, _Function: FnOnce(T) -> OptionalArg<_Other>>( self, f: _Function, ) -> OptionalArg<_Other>

Source

pub fn zip<_Other>(self, other: OptionalArg<_Other>) -> OptionalArg<(T, _Other)>

Source

pub fn take(&mut self) -> Self
where T: Default,

Source

pub fn unwrap_or_default(self) -> T
where T: Default,

Source§

impl<T> OptionalArg<&T>
where T: Copy,

Source

pub fn copied(self) -> OptionalArg<T>

Source§

impl<T> OptionalArg<&mut T>
where T: Copy,

Source

pub fn copied(self) -> OptionalArg<T>

Source§

impl<T> OptionalArg<&T>
where T: Clone,

Source

pub fn cloned(self) -> OptionalArg<T>

Source§

impl<T> OptionalArg<&mut T>
where T: Clone,

Source

pub fn cloned(self) -> OptionalArg<T>

Source§

impl<T> OptionalArg<T>
where T: Deref,

Source

pub fn as_deref(&self) -> OptionalArg<&T::Target>

Source§

impl<T: DerefMut> OptionalArg<T>

Source

pub fn as_deref_mut(&mut self) -> OptionalArg<&mut T::Target>

Source§

impl<T, _Error> OptionalArg<Result<T, _Error>>

Source

pub fn transpose(self) -> Result<OptionalArg<T>, _Error>

Source§

impl<T> OptionalArg<T>

Source

pub const fn is_present(&self) -> bool

Returns true if self is of variant Present.

Source

pub fn as_present(&self) -> Option<&T>

Returns Some if self is a reference of variant Present, and None otherwise.

Source

pub fn as_mut_present(&mut self) -> Option<&mut T>

Returns Some if self is a mutable reference of variant Present, and None otherwise.

Source

pub fn expect_present(self) -> T
where Self: Debug,

Unwraps the value, yielding the content of Present.

§Panics

Panics if the value is not Present. In debug builds the panic message includes the content of self.

Source

pub fn present(self) -> Option<T>

Returns Some if self is of variant Present, and None otherwise.

Source

pub const fn is_missing(&self) -> bool

Returns true if self is of variant Missing.

Source§

impl OptionalArg<PyObjectRef>

Source§

impl<T> OptionalArg<Option<T>>

Source

pub fn flatten(self) -> Option<T>

Source§

impl<T> OptionalArg<ArgStrictInt<T>>

Trait Implementations§

Source§

impl<T> Clone for OptionalArg<T>
where T: Clone,

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Copy for OptionalArg<T>
where T: Copy,

Source§

impl<T: Debug> Debug for OptionalArg<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Default for OptionalArg<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> From<Option<T>> for OptionalArg<T>

Source§

fn from(value: Option<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<OptionalArg<T>> for Option<T>

Source§

fn from(value: OptionalArg<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> From<T> for OptionalArg<T>

Source§

fn from(value: T) -> Self

Converts to this type from the input type.
Source§

impl<T: TryFromObject> FromArgOptional for OptionalArg<T>

Source§

type Inner = T

Source§

fn from_inner(x: T) -> Self

Source§

impl<T> FromArgs for OptionalArg<T>
where T: TryFromObject,

Source§

const PARAMS: Option<&'static [Param]>

Parameters this type contributes to a text signature. Read more
Source§

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>

Extracts this item from the next argument(s).
Source§

impl<T> IntoIterator for OptionalArg<T>

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> IntoIter<T> ⓘ

Creates an iterator from a value. Read more
Source§

impl<T> OptionLike for OptionalArg<T>

Source§

impl<T> OptionalArgDefault for OptionalArg<T>

Source§

const PY_DEFAULT: DefaultRepr = super::signature::DefaultRepr::Unrepresentable

Source§

impl<T> Traverse for OptionalArg<T>
where T: Traverse,

Source§

fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)

impl traverse() with caution! Following those guideline so traverse doesn’t cause memory error!: Read more
Source§

fn clear(&mut self, _out: &mut Vec<PyObjectRef>)

Extract all owned child PyObjectRefs for circular reference resolution (tp_clear). Called just before object deallocation to break circular references. Default implementation does nothing.

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> UnsafeUnpin for OptionalArg<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for OptionalArg<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<I, C> CompactStringExt for C
where I: AsRef<str>, C: IntoIterator<Item = I>,

Source§

fn concat_compact(self) -> CompactString

Concatenates all the items of a collection into a CompactString Read more
Source§

fn join_compact<S>(self, separator: S) -> CompactString
where S: AsRef<str>,

Joins all the items of a collection, placing a separator between them, forming a CompactString Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

impl<T, U> ExactInto<U> for T
where U: ExactFrom<T>,

Source§

fn exact_into(self) -> U

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Helper for T

Source§

impl<T, U> ImaginaryInto<U> for T
where U: ImaginaryFrom<T>,

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T, U> OverflowingInto<U> for T
where U: OverflowingFrom<T>,

Source§

impl<T> PrimitiveIntRandomBounds for T

Source§

impl<T> PrimitiveSignedRandomBounds for T

Source§

impl<T> PyThreadingConstraint for T

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> RoundingInto<U> for T
where U: RoundingFrom<T>,

Source§

impl<T, U> SaturatingInto<U> for T
where U: SaturatingFrom<T>,

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T, U> WrappingInto<U> for T
where U: WrappingFrom<T>,

Source§

fn wrapping_into(self) -> U