Trait pyo3::ObjectProtocol [] [src]

pub trait ObjectProtocol {
    fn hasattr<N>(&self, attr_name: N) -> PyResult<bool>
    where
        N: ToPyObject
;
fn getattr<N>(&self, attr_name: N) -> PyResult<&PyObjectRef>
    where
        N: ToPyObject
;
fn setattr<N, V>(&self, attr_name: N, value: V) -> PyResult<()>
    where
        N: ToBorrowedObject,
        V: ToBorrowedObject
;
fn delattr<N>(&self, attr_name: N) -> PyResult<()>
    where
        N: ToPyObject
;
fn compare<O>(&self, other: O) -> PyResult<Ordering>
    where
        O: ToPyObject
;
fn rich_compare<O>(
        &self,
        other: O,
        compare_op: CompareOp
    ) -> PyResult<PyObject>
    where
        O: ToPyObject
;
fn repr(&self) -> PyResult<&PyString>;
fn str(&self) -> PyResult<&PyString>;
fn is_callable(&self) -> bool;
fn call<A, K>(&self, args: A, kwargs: K) -> PyResult<&PyObjectRef>
    where
        A: IntoPyTuple,
        K: IntoPyDictPointer
;
fn call0(&self) -> PyResult<&PyObjectRef>;
fn call1<A>(&self, args: A) -> PyResult<&PyObjectRef>
    where
        A: IntoPyTuple
;
fn call_method<A, K>(
        &self,
        name: &str,
        args: A,
        kwargs: K
    ) -> PyResult<&PyObjectRef>
    where
        A: IntoPyTuple,
        K: IntoPyDictPointer
;
fn call_method0(&self, name: &str) -> PyResult<&PyObjectRef>;
fn call_method1<A: IntoPyTuple>(
        &self,
        name: &str,
        args: A
    ) -> PyResult<&PyObjectRef>;
fn hash(&self) -> PyResult<isize>;
fn is_true(&self) -> PyResult<bool>;
fn is_none(&self) -> bool;
fn len(&self) -> PyResult<usize>;
fn get_item<K>(&self, key: K) -> PyResult<&PyObjectRef>
    where
        K: ToBorrowedObject
;
fn set_item<K, V>(&self, key: K, value: V) -> PyResult<()>
    where
        K: ToBorrowedObject,
        V: ToBorrowedObject
;
fn del_item<K>(&self, key: K) -> PyResult<()>
    where
        K: ToBorrowedObject
;
fn iter(&self) -> PyResult<PyIterator>;
fn get_type(&self) -> &PyType;
fn get_base(&self) -> &Self::BaseType
    where
        Self: PyTypeInfo
;
fn get_mut_base(&self) -> &mut Self::BaseType
    where
        Self: PyTypeInfo
;
fn cast_as<'a, D>(&'a self) -> Result<&'a D, <D as PyTryFrom>::Error>
    where
        D: PyTryFrom<Error = PyDowncastError>,
        &'a PyObjectRef: From<&'a Self>
;
fn extract<'a, D>(&'a self) -> PyResult<D>
    where
        D: FromPyObject<'a>,
        &'a PyObjectRef: From<&'a Self>
;
fn get_refcnt(&self) -> isize;
fn None(&self) -> PyObject; }

Python object model helper methods

Required Methods

Determines whether this object has the given attribute. This is equivalent to the Python expression 'hasattr(self, attr_name)'.

Retrieves an attribute value. This is equivalent to the Python expression 'self.attr_name'.

Sets an attribute value. This is equivalent to the Python expression 'self.attr_name = value'.

Deletes an attribute. This is equivalent to the Python expression 'del self.attr_name'.

Compares two Python objects.

On Python 2, this is equivalent to the Python expression 'cmp(self, other)'.

On Python 3, this is equivalent to: if self == other: return Equal elif a < b: return Less elif a > b: return Greater else: raise TypeError("ObjectProtocol::compare(): All comparisons returned false")

Compares two Python objects.

Depending on the value of compare_op, equivalent to one of the following Python expressions: * CompareOp::Eq: self == other * CompareOp::Ne: self != other * CompareOp::Lt: self < other * CompareOp::Le: self <= other * CompareOp::Gt: self > other * CompareOp::Ge: self >= other

Compute the string representation of self. This is equivalent to the Python expression 'repr(self)'.

Compute the string representation of self. This is equivalent to the Python expression 'str(self)'.

Determines whether this object is callable.

Calls the object. This is equivalent to the Python expression: 'self(*args, **kwargs)'

Calls the object. This is equivalent to the Python expression: 'self()'

Calls the object. This is equivalent to the Python expression: 'self(*args)'

Calls a method on the object. This is equivalent to the Python expression: 'self.name(*args, **kwargs)'

Example

Be careful when using this code, it's not being tested!
let obj = SomePyObject::new();
let args = (arg1, arg2, arg3);
let kwargs = ((key1, value1), (key2, value2));
let pid = obj.call_mwthod("do_something", args, kwargs);

Calls a method on the object. This is equivalent to the Python expression: 'self.name()'

Calls a method on the object with positional arguments only . This is equivalent to the Python expression: 'self.name(*args)'

Retrieves the hash code of the object. This is equivalent to the Python expression: 'hash(self)'

Returns whether the object is considered to be true. This is equivalent to the Python expression: 'not not self'

Returns whether the object is considered to be None. This is equivalent to the Python expression: 'is None'

Returns the length of the sequence or mapping. This is equivalent to the Python expression: 'len(self)'

This is equivalent to the Python expression: 'self[key]'

Sets an item value. This is equivalent to the Python expression 'self[key] = value'.

Deletes an item. This is equivalent to the Python expression 'del self[key]'.

Takes an object and returns an iterator for it. This is typically a new iterator but if the argument is an iterator, this returns itself.

Gets the Python type object for this object's type.

Gets the Python base object for this object.

Gets the Python base object for this object.

Casts the PyObject to a concrete Python object type.

Extracts some type from the Python object. This is a wrapper function around FromPyObject::extract().

Returns reference count for python object.

Gets the Python builtin value None.

Implementors