pub enum Either<A, B> {
A(A),
B(B),
}
Variants§
Trait Implementations§
Source§impl<A: Into<PyObjectRef>, B: Into<PyObjectRef>> From<Either<A, B>> for PyObjectRef
impl<A: Into<PyObjectRef>, B: Into<PyObjectRef>> From<Either<A, B>> for PyObjectRef
Source§impl<A: ToPyObject, B: ToPyObject> ToPyObject for Either<A, B>
impl<A: ToPyObject, B: ToPyObject> ToPyObject for Either<A, B>
fn to_pyobject(self, vm: &VirtualMachine) -> PyObjectRef
Source§impl<A: Traverse, B: Traverse> Traverse for Either<A, B>
impl<A: Traverse, B: Traverse> Traverse for Either<A, B>
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 moreSource§impl<A, B> TryFromObject for Either<A, B>where
A: TryFromObject,
B: TryFromObject,
This allows a builtin method to accept arguments that may be one of two
types, raising a TypeError
if it is neither.
impl<A, B> TryFromObject for Either<A, B>where
A: TryFromObject,
B: TryFromObject,
This allows a builtin method to accept arguments that may be one of two
types, raising a TypeError
if it is neither.
§Example
use rustpython_vm::VirtualMachine;
use rustpython_vm::builtins::{PyStrRef, PyIntRef};
use rustpython_vm::function::Either;
fn do_something(arg: Either<PyIntRef, PyStrRef>, vm: &VirtualMachine) {
match arg {
Either::A(int)=> {
// do something with int
}
Either::B(string) => {
// do something with string
}
}
}
Source§fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>
Attempt to convert a Python object to a value of this type.
Auto Trait Implementations§
impl<A, B> Freeze for Either<A, B>
impl<A, B> RefUnwindSafe for Either<A, B>where
A: RefUnwindSafe,
B: RefUnwindSafe,
impl<A, B> Send for Either<A, B>
impl<A, B> Sync for Either<A, B>
impl<A, B> Unpin for Either<A, B>
impl<A, B> UnwindSafe for Either<A, B>where
A: UnwindSafe,
B: UnwindSafe,
Blanket Implementations§
Source§impl<T> AsObject for T
impl<T> AsObject for T
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> FromArgOptional for Twhere
T: TryFromObject,
impl<T> FromArgOptional for Twhere
T: TryFromObject,
Source§impl<T> FromArgs for Twhere
T: TryFromObject,
impl<T> FromArgs for Twhere
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<T, ArgumentError>
fn from_args( vm: &VirtualMachine, args: &mut FuncArgs, ) -> Result<T, ArgumentError>
Extracts this item from the next argument(s).
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