[][src]Trait rustpython_vm::pyobject::TryFromObject

pub trait TryFromObject: Sized {
    fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>;
}

Implemented by any type that can be created from a Python object.

Any type that implements TryFromObject is automatically FromArgs, and so can be accepted as a argument to a built-in function.

Required methods

fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>

Attempt to convert a Python object to a value of this type.

Loading content...

Implementations on Foreign Types

impl TryFromObject for bool[src]

impl TryFromObject for f32[src]

impl TryFromObject for f64[src]

impl TryFromObject for isize[src]

impl TryFromObject for i8[src]

impl TryFromObject for i16[src]

impl TryFromObject for i32[src]

impl TryFromObject for i64[src]

impl TryFromObject for usize[src]

impl TryFromObject for u8[src]

impl TryFromObject for u16[src]

impl TryFromObject for u32[src]

impl TryFromObject for u64[src]

impl<T: TryFromObject> TryFromObject for Option<T>[src]

impl TryFromObject for Duration[src]

Loading content...

Implementors

impl TryFromObject for ExceptionCtor[src]

impl TryFromObject for PyBytesLike[src]

impl TryFromObject for RangeIndex[src]

impl TryFromObject for SequenceIndex[src]

impl TryFromObject for IntoPyBool[src]

impl TryFromObject for PyByteInner[src]

impl TryFromObject for IntoPyFloat[src]

impl TryFromObject for PyCallable[src]

impl TryFromObject for PyObjectRef[src]

impl<A, B> TryFromObject for Either<A, B> where
    A: TryFromObject,
    B: TryFromObject
[src]

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::obj::{objstr::PyStringRef, objint::PyIntRef};
use rustpython_vm::pyobject::Either;

fn do_something(arg: Either<PyIntRef, PyStringRef>, vm: &VirtualMachine) {
    match arg {
        Either::A(int)=> {
            // do something with int
        }
        Either::B(string) => {
            // do something with string
        }
    }
}

impl<T> TryFromObject for PyIterable<T> where
    T: TryFromObject
[src]

impl<T> TryFromObject for PyRef<T> where
    T: PyValue
[src]

Loading content...