Trait TryFromObject

Source
pub trait TryFromObject: Sized {
    // Required method
    fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>;
}
Expand description

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§

Source

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

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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl TryFromObject for Option<Gid>

Source§

impl TryFromObject for Option<Uid>

Source§

impl TryFromObject for f32

Source§

impl TryFromObject for f64

Source§

impl TryFromObject for Duration

Source§

impl TryFromObject for BorrowedFd<'_>

Source§

impl<T: TryFromObject> TryFromObject for Option<T>

Implementors§

Source§

impl TryFromObject for ExceptionCtor

Source§

impl TryFromObject for ArgAsciiBuffer

Source§

impl TryFromObject for ArgStrOrBytesLike

Source§

impl TryFromObject for FsPath

Source§

impl TryFromObject for ArgCallable

Source§

impl TryFromObject for ArgIndex

Source§

impl TryFromObject for ArgIntoBool

Source§

impl TryFromObject for ArgIntoComplex

Source§

impl TryFromObject for ArgIntoFloat

Source§

impl TryFromObject for ArgMapping

Source§

impl TryFromObject for PyObjectRef

Source§

impl TryFromObject for OsPath

Source§

impl TryFromObject for PyIter<PyObjectRef>

Source§

impl TryFromObject for Fildes

Source§

impl<A, B> TryFromObject for Either<A, B>

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§

impl<T> TryFromObject for ArgIterable<T>
where T: TryFromObject,

Source§

impl<T> TryFromObject for ArgPrimitiveIndex<T>
where T: PrimInt + for<'a> TryFrom<&'a BigInt>,

Source§

impl<T> TryFromObject for PyRef<T>
where T: PyPayload,

Source§

impl<T: PyPayload> TryFromObject for PyRefExact<T>

Source§

impl<T: TryFromObject> TryFromObject for PyArithmeticValue<T>

Source§

impl<T: TryFromObject> TryFromObject for ArgSequence<T>

Source§

impl<T: for<'a> TryFromBorrowedObject<'a>> TryFromObject for T

Rust-side only version of TryFromObject to reduce unnecessary Rc::clone

Morty Proxy This is a proxified and sanitized view of the page, visit original site.