pub enum Either<A, B> {
    A(A),
    B(B),
}

Variants§

§

A(A)

§

B(B)

Trait Implementations§

source§

impl<A: AsRef<PyObject>, B: AsRef<PyObject>> AsRef<PyObject> for Either<A, B>

source§

fn as_ref(&self) -> &PyObject

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<A: Borrow<PyObject>, B: Borrow<PyObject>> Borrow<PyObject> for Either<A, B>

source§

fn borrow(&self) -> &PyObject

Immutably borrows from an owned value. Read more
source§

impl<A: Into<PyObjectRef>, B: Into<PyObjectRef>> From<Either<A, B>> for PyObjectRef

source§

fn from(value: Either<A, B>) -> Self

Converts to this type from the input type.
source§

impl<A: ToPyObject, B: ToPyObject> ToPyObject for Either<A, B>

source§

impl<A: Traverse, B: Traverse> Traverse for Either<A, B>

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§

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>

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AsObject for Twhere T: Borrow<PyObject>,

source§

fn as_object(&self) -> &PyObject

source§

fn get_id(&self) -> usize

source§

fn is<T>(&self, other: &T) -> boolwhere T: AsObject,

source§

fn class(&self) -> &Py<PyType>

source§

fn get_class_attr( &self, attr_name: &'static PyStrInterned ) -> Option<PyObjectRef>

source§

fn fast_isinstance(&self, cls: &Py<PyType>) -> bool

Determines if obj actually an instance of cls, this doesn’t call instancecheck, so only use this if cls is known to have not overridden the base instancecheck magic method.
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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>,

§

fn exact_from(value: T) -> U

§

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

§

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> FromArgOptional for Twhere T: TryFromObject,

§

type Inner = T

source§

fn from_inner(x: T) -> T

source§

impl<T> FromArgs for Twhere T: TryFromObject,

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<T, ArgumentError>

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

impl<T, U> Into<U> for Twhere 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> IntoObject for Twhere T: Into<PyObjectRef>,

§

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

§

fn overflowing_into(self) -> (U, bool)

§

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

§

fn rounding_into(self, rm: RoundingMode) -> U

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

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

§

fn saturating_into(self) -> U

source§

impl<T> ToPyResult for Twhere T: ToPyObject,

source§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

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

§

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

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

§

fn wrapping_into(self) -> U

source§

impl<T> PyThreadingConstraint for T