Struct PyObjectRef

Source
pub struct PyObjectRef { /* private fields */ }
Expand description

The PyObjectRef is one of the most used types. It is a reference to a python object. A single python object can have multiple references, and this reference counting is accounted for by this type. Use the .clone() method to create a new reference and increment the amount of references to the python object by 1.

Implementations§

Source§

impl PyObjectRef

Source

pub fn try_complex( &self, vm: &VirtualMachine, ) -> PyResult<Option<(Complex64, bool)>>

Tries converting a python object into a complex, returns an option of whether the complex and whether the object was a complex originally or coereced into one

Source§

impl PyObjectRef

Source

pub fn try_to_bool(self, vm: &VirtualMachine) -> PyResult<bool>

Convert Python bool into Rust bool.

Source§

impl PyObjectRef

Source

pub fn try_into_value<T>(self, vm: &VirtualMachine) -> PyResult<T>
where T: TryFromObject,

Source§

impl PyObjectRef

Source

pub fn into_raw(self) -> *const PyObject

Source

pub unsafe fn from_raw(ptr: *const PyObject) -> Self

§Safety

The raw pointer must have been previously returned from a call to PyObjectRef::into_raw. The user is responsible for ensuring that the inner data is not dropped more than once due to mishandling the reference count by calling this function too many times.

Source

pub fn downcast<T: PyObjectPayload>(self) -> Result<PyRef<T>, Self>

Attempt to downcast this reference to a subclass.

If the downcast fails, the original ref is returned in as Err so another downcast can be attempted without unnecessary cloning.

Source

pub fn downcast_ref<T: PyObjectPayload>(&self) -> Option<&Py<T>>

Source

pub unsafe fn downcast_unchecked<T: PyObjectPayload>(self) -> PyRef<T>

Force to downcast this reference to a subclass.

§Safety

T must be the exact payload type

Source

pub unsafe fn downcast_unchecked_ref<T: PyObjectPayload>(&self) -> &Py<T>

§Safety

T must be the exact payload type

Source

pub fn downcast_exact<T: PyObjectPayload + PyPayload>( self, vm: &VirtualMachine, ) -> Result<PyRefExact<T>, Self>

Attempt to downcast this reference to the specific class that is associated T.

If the downcast fails, the original ref is returned in as Err so another downcast can be attempted without unnecessary cloning.

Source§

impl PyObjectRef

Source

pub fn rich_compare( self, other: Self, opid: PyComparisonOp, vm: &VirtualMachine, ) -> PyResult

Source

pub fn bytes(self, vm: &VirtualMachine) -> PyResult

Source

pub fn is_true(self, vm: &VirtualMachine) -> PyResult<bool>

Source

pub fn not(self, vm: &VirtualMachine) -> PyResult<bool>

Source

pub fn length_hint( self, defaultvalue: usize, vm: &VirtualMachine, ) -> PyResult<usize>

Source

pub fn dir(self, vm: &VirtualMachine) -> PyResult<PyList>

Methods from Deref<Target = PyObject>§

Source

pub fn try_to_value<'a, T>(&'a self, vm: &VirtualMachine) -> PyResult<T>
where T: 'a + TryFromBorrowedObject<'a>,

Source

pub fn try_to_ref<'a, T>(&'a self, vm: &VirtualMachine) -> PyResult<&'a Py<T>>
where T: 'a + PyPayload,

Source

pub fn try_value_with<T, F, R>(&self, f: F, vm: &VirtualMachine) -> PyResult<R>
where T: PyPayload, F: Fn(&T) -> PyResult<R>,

Source

pub fn try_bytes_like<R>( &self, vm: &VirtualMachine, f: impl FnOnce(&[u8]) -> R, ) -> PyResult<R>

Source

pub fn try_rw_bytes_like<R>( &self, vm: &VirtualMachine, f: impl FnOnce(&mut [u8]) -> R, ) -> PyResult<R>

Source

pub fn as_interned_str( &self, vm: &VirtualMachine, ) -> Option<&'static PyStrInterned>

Source

pub fn downgrade( &self, callback: Option<PyObjectRef>, vm: &VirtualMachine, ) -> PyResult<PyRef<PyWeak>>

Source

pub fn get_weak_references(&self) -> Option<Vec<PyRef<PyWeak>>>

Source

pub fn payload_is<T: PyObjectPayload>(&self) -> bool

Source

pub unsafe fn payload_unchecked<T: PyObjectPayload>(&self) -> &T

Force to return payload as T.

§Safety

The actual payload type must be T.

Source

pub fn payload<T: PyObjectPayload>(&self) -> Option<&T>

Source

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

Source

pub fn set_class(&self, typ: PyTypeRef, vm: &VirtualMachine)

Source

pub fn payload_if_exact<T: PyObjectPayload + PyPayload>( &self, vm: &VirtualMachine, ) -> Option<&T>

Source

pub fn dict(&self) -> Option<PyDictRef>

Source

pub fn set_dict(&self, dict: PyDictRef) -> Result<(), PyDictRef>

Set the dict field. Returns Err(dict) if this object does not have a dict field in the first place.

Source

pub fn payload_if_subclass<T: PyPayload>( &self, vm: &VirtualMachine, ) -> Option<&T>

Source

pub fn downcast_ref<T: PyObjectPayload>(&self) -> Option<&Py<T>>

Source

pub fn downcast_ref_if_exact<T: PyObjectPayload + PyPayload>( &self, vm: &VirtualMachine, ) -> Option<&Py<T>>

Source

pub unsafe fn downcast_unchecked_ref<T: PyObjectPayload>(&self) -> &Py<T>

§Safety

T must be the exact payload type

Source

pub fn strong_count(&self) -> usize

Source

pub fn weak_count(&self) -> Option<usize>

Source

pub fn as_raw(&self) -> *const PyObject

Source

pub fn to_callable(&self) -> Option<PyCallable<'_>>

Source

pub fn is_callable(&self) -> bool

Source

pub fn call(&self, args: impl IntoFuncArgs, vm: &VirtualMachine) -> PyResult

PyObject_CallArg series

Source

pub fn call_with_args(&self, args: FuncArgs, vm: &VirtualMachine) -> PyResult

PyObject_Call

Source

pub fn to_mapping(&self) -> PyMapping<'_>

Source

pub fn to_number(&self) -> PyNumber<'_>

Source

pub fn try_index_opt(&self, vm: &VirtualMachine) -> Option<PyResult<PyIntRef>>

Source

pub fn try_index(&self, vm: &VirtualMachine) -> PyResult<PyIntRef>

Source

pub fn try_int(&self, vm: &VirtualMachine) -> PyResult<PyIntRef>

Source

pub fn try_float_opt( &self, vm: &VirtualMachine, ) -> Option<PyResult<PyRef<PyFloat>>>

Source

pub fn try_float(&self, vm: &VirtualMachine) -> PyResult<PyRef<PyFloat>>

Source

pub fn get_iter(&self, vm: &VirtualMachine) -> PyResult<PyIter>

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.

Source

pub fn get_aiter(&self, vm: &VirtualMachine) -> PyResult

Source

pub fn has_attr<'a>( &self, attr_name: impl AsPyStr<'a>, vm: &VirtualMachine, ) -> PyResult<bool>

Source

pub fn get_attr<'a>( &self, attr_name: impl AsPyStr<'a>, vm: &VirtualMachine, ) -> PyResult

Source

pub fn call_set_attr( &self, vm: &VirtualMachine, attr_name: &Py<PyStr>, attr_value: PySetterValue, ) -> PyResult<()>

Source

pub fn set_attr<'a>( &self, attr_name: impl AsPyStr<'a>, attr_value: impl Into<PyObjectRef>, vm: &VirtualMachine, ) -> PyResult<()>

Source

pub fn generic_setattr( &self, attr_name: &Py<PyStr>, value: PySetterValue, vm: &VirtualMachine, ) -> PyResult<()>

Source

pub fn generic_getattr(&self, name: &Py<PyStr>, vm: &VirtualMachine) -> PyResult

Source

pub fn generic_getattr_opt( &self, name_str: &Py<PyStr>, dict: Option<PyDictRef>, vm: &VirtualMachine, ) -> PyResult<Option<PyObjectRef>>

CPython _PyObject_GenericGetAttrWithDict

Source

pub fn del_attr<'a>( &self, attr_name: impl AsPyStr<'a>, vm: &VirtualMachine, ) -> PyResult<()>

Source

pub fn rich_compare_bool( &self, other: &Self, opid: PyComparisonOp, vm: &VirtualMachine, ) -> PyResult<bool>

Source

pub fn repr(&self, vm: &VirtualMachine) -> PyResult<PyStrRef>

Source

pub fn ascii(&self, vm: &VirtualMachine) -> PyResult<AsciiString>

Source

pub fn str(&self, vm: &VirtualMachine) -> PyResult<PyStrRef>

Source

pub fn is_subclass(&self, cls: &PyObject, vm: &VirtualMachine) -> PyResult<bool>

Determines if self is a subclass of cls, either directly, indirectly or virtually via the subclasscheck magic method.

Source

pub fn is_instance(&self, cls: &PyObject, vm: &VirtualMachine) -> PyResult<bool>

Determines if self is an instance of cls, either directly, indirectly or virtually via the instancecheck magic method.

Source

pub fn hash(&self, vm: &VirtualMachine) -> PyResult<PyHash>

Source

pub fn obj_type(&self) -> PyObjectRef

Source

pub fn type_check(&self, typ: &Py<PyType>) -> bool

Source

pub fn length_opt(&self, vm: &VirtualMachine) -> Option<PyResult<usize>>

Source

pub fn length(&self, vm: &VirtualMachine) -> PyResult<usize>

Source

pub fn get_item<K: DictKey + ?Sized>( &self, needle: &K, vm: &VirtualMachine, ) -> PyResult

Source

pub fn set_item<K: DictKey + ?Sized>( &self, needle: &K, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()>

Source

pub fn del_item<K: DictKey + ?Sized>( &self, needle: &K, vm: &VirtualMachine, ) -> PyResult<()>

Source

pub fn to_sequence(&self) -> PySequence<'_>

Trait Implementations§

Source§

impl AsRef<PyObject> for PyObjectRef

Source§

fn as_ref(&self) -> &PyObject

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

impl Borrow<PyObject> for PyObjectRef

Source§

fn borrow(&self) -> &PyObject

Immutably borrows from an owned value. Read more
Source§

impl Clone for PyObjectRef

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for PyObjectRef

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Deref for PyObjectRef

Source§

type Target = PyObject

The resulting type after dereferencing.
Source§

fn deref(&self) -> &PyObject

Dereferences the value.
Source§

impl Drop for PyObjectRef

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Dumpable for PyObjectRef

Source§

type Error = DumpError

Source§

type Constant = Literal

Source§

fn with_dump<R>( &self, f: impl FnOnce(DumpableValue<'_, Self>) -> R, ) -> Result<R, Self::Error>

Source§

impl From<ArgCallable> for PyObjectRef

Source§

fn from(value: ArgCallable) -> PyObjectRef

Converts to this type from the input type.
Source§

impl From<ArgMapping> for PyObjectRef

Source§

fn from(value: ArgMapping) -> PyObjectRef

Converts to this type from the input type.
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 From<PyIter> for PyObjectRef

Source§

fn from(value: PyIter<PyObjectRef>) -> PyObjectRef

Converts to this type from the input type.
Source§

impl From<PyObjectRef> for PyAtomicRef<PyObject>

Source§

fn from(obj: PyObjectRef) -> Self

Converts to this type from the input type.
Source§

impl From<PyObjectRef> for PyClassMethod

Source§

fn from(callable: PyObjectRef) -> Self

Converts to this type from the input type.
Source§

impl From<PyObjectRef> for PyStaticMethod

Source§

fn from(callable: PyObjectRef) -> Self

Converts to this type from the input type.
Source§

impl<T> From<PyRef<T>> for PyObjectRef
where T: PyObjectPayload,

Source§

fn from(value: PyRef<T>) -> Self

Converts to this type from the input type.
Source§

impl FromIterator<PyObjectRef> for PyList

Source§

fn from_iter<T: IntoIterator<Item = PyObjectRef>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl ToPyObject for PyObjectRef

Source§

impl Traverse for PyObjectRef

Source§

fn traverse(&self, traverse_fn: &mut TraverseFn<'_>)

impl traverse() with caution! Following those guideline so traverse doesn’t cause memory error!: Read more
Source§

impl TryFromObject for PyObjectRef

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§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn as_object(&self) -> &PyObject

Source§

fn get_id(&self) -> usize

Source§

fn is<T>(&self, other: &T) -> bool
where 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 T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, U> ExactFrom<T> for U
where U: TryFrom<T>,

Source§

fn exact_from(value: T) -> U

Source§

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

Source§

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 T
where T: TryFromObject,

Source§

type Inner = T

Source§

fn from_inner(x: T) -> T

Source§

impl<T> FromArgs for T
where 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 T
where 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoObject for T
where T: Into<PyObjectRef>,

Source§

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

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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

Source§

impl<T> ToDebugString for T
where T: Debug,

Source§

fn to_debug_string(&self) -> String

Returns the String produced by Ts Debug implementation.

§Examples
use malachite_base::strings::ToDebugString;

assert_eq!([1, 2, 3].to_debug_string(), "[1, 2, 3]");
assert_eq!(
    [vec![2, 3], vec![], vec![4]].to_debug_string(),
    "[[2, 3], [], [4]]"
);
assert_eq!(Some(5).to_debug_string(), "Some(5)");
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToPyResult for T
where T: ToPyObject,

Source§

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

Source§

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 T
where U: TryFrom<T>,

Source§

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

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

Source§

fn vzip(self) -> V

Source§

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

Source§

fn wrapping_into(self) -> U

Source§

impl<T> PyThreadingConstraint for T

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