Enum rustpython_vm::function::Either
source · 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,
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> RefUnwindSafe for Either<A, B>where A: RefUnwindSafe, B: RefUnwindSafe,
impl<A, B> Send for Either<A, B>where A: Send, B: Send,
impl<A, B> Sync for Either<A, B>where A: Sync, B: Sync,
impl<A, B> Unpin for Either<A, B>where A: Unpin, B: Unpin,
impl<A, B> UnwindSafe for Either<A, B>where A: UnwindSafe, B: UnwindSafe,
Blanket Implementations§
source§impl<T> AsObject for Twhere
T: Borrow<PyObject>,
impl<T> AsObject for Twhere T: Borrow<PyObject>,
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
§impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> ExactFrom<T> for Uwhere U: TryFrom<T>,
fn exact_from(value: T) -> U
§impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
impl<T, U> ExactInto<U> for Twhere U: ExactFrom<T>,
fn exact_into(self) -> U
source§impl<T> FromArgOptional for Twhere
T: TryFromObject,
impl<T> FromArgOptional for Twhere T: TryFromObject,
type Inner = T
fn from_inner(x: T) -> T
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).