pub struct PyRef<T> { /* private fields */ }Expand description
A reference to a Python object.
Note that a PyRef<T> can only deref to a shared / immutable reference.
It is the payload type’s responsibility to handle (possibly concurrent)
mutability with locks or concurrent data structures if required.
A PyRef<T> can be directly returned from a built-in function to handle
situations (such as when implementing in-place methods such as __iadd__)
where a reference to the same object must be returned.
Implementations§
Source§impl PyRef<PyStr>
impl PyRef<PyStr>
pub fn is_empty(&self) -> bool
pub fn concat_in_place(&mut self, other: &Wtf8, vm: &VirtualMachine)
pub fn try_into_utf8(self, vm: &VirtualMachine) -> PyResult<PyRef<PyUtf8Str>>
Source§impl PyRef<PyTuple<PyObjectRef>>
impl PyRef<PyTuple<PyObjectRef>>
pub fn try_into_typed<T: PyPayload>( self, vm: &VirtualMachine, ) -> PyResult<PyRef<PyTuple<PyRef<T>>>>
Source§impl<T: PySubclass + Debug> PyRef<T>
impl<T: PySubclass + Debug> PyRef<T>
Source§impl<T: PyPayload> PyRef<T>
impl<T: PyPayload> PyRef<T>
pub fn into_exact_or( self, ctx: &Context, f: impl FnOnce(Self) -> PyRefExact<T>, ) -> PyRefExact<T>
Source§impl PyRef<VecBuffer>
impl PyRef<VecBuffer>
pub fn into_pybuffer(self, readonly: bool) -> PyBuffer
pub fn into_pybuffer_with_descriptor(self, desc: BufferDescriptor) -> PyBuffer
Methods from Deref<Target = Py<T>>§
pub fn downgrade( &self, callback: Option<PyObjectRef>, vm: &VirtualMachine, ) -> PyResult<PyWeakRef<T>>
pub fn payload(&self) -> &T
Sourcepub fn upcast_ref<U: PyPayload + StaticType>(&self) -> &Py<U>where
T: StaticType,
pub fn upcast_ref<U: PyPayload + StaticType>(&self) -> &Py<U>where
T: StaticType,
Converts &Py<T> to &Py<U> where U is an ancestor type.
Trait Implementations§
Source§impl From<PyRef<PyBaseException>> for ArgumentError
impl From<PyRef<PyBaseException>> for ArgumentError
Source§fn from(ex: PyBaseExceptionRef) -> Self
fn from(ex: PyBaseExceptionRef) -> Self
Converts to this type from the input type.
Source§impl<T> From<PyRef<T>> for PyObjectRef
impl<T> From<PyRef<T>> for PyObjectRef
Source§impl<T: PyPayload> ToPyObject for PyRef<T>
impl<T: PyPayload> ToPyObject for PyRef<T>
fn to_pyobject(self, _vm: &VirtualMachine) -> PyObjectRef
Source§impl<T: PyPayload> TransmuteFromObject for PyRef<T>
impl<T: PyPayload> TransmuteFromObject for PyRef<T>
Source§impl<T: PyObjectPayload> Traverse for PyRef<T>
impl<T: PyObjectPayload> Traverse for PyRef<T>
Source§fn traverse(&self, traverse_fn: &mut TraverseFn<'_>)
fn traverse(&self, traverse_fn: &mut TraverseFn<'_>)
impl
traverse() with caution! Following those guideline so traverse doesn’t cause memory error!: Read moreSource§fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
Extract all owned child PyObjectRefs for circular reference resolution (tp_clear).
Called just before object deallocation to break circular references.
Default implementation does nothing.
Source§impl<T> TryFromObject for PyRef<T>where
T: PyPayload,
impl<T> TryFromObject for PyRef<T>where
T: PyPayload,
Source§fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>
fn try_from_object(vm: &VirtualMachine, obj: PyObjectRef) -> PyResult<Self>
Attempt to convert a Python object to a value of this type.
impl<T> Eq for PyRef<T>
Auto Trait Implementations§
impl<T> Freeze for PyRef<T>
impl<T> !RefUnwindSafe for PyRef<T>
impl<T> !Send for PyRef<T>
impl<T> !Sync for PyRef<T>
impl<T> Unpin for PyRef<T>
impl<T> UnsafeUnpin for PyRef<T>
impl<T> !UnwindSafe for PyRef<T>
Blanket Implementations§
Source§impl<T> AsObject for T
impl<T> AsObject for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> FromArgOptional for Twhere
T: TryFromObject,
impl<T> FromArgOptional for Twhere
T: TryFromObject,
Source§impl<T> FromArgs for Twhere
T: TryFromObject,
impl<T> FromArgs for Twhere
T: TryFromObject,
Source§fn arity() -> RangeInclusive<usize>
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>
fn from_args( vm: &VirtualMachine, args: &mut FuncArgs, ) -> Result<T, ArgumentError>
Extracts this item from the next argument(s).
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoObject for Twhere
T: Into<PyObjectRef>,
impl<T> IntoObject for Twhere
T: Into<PyObjectRef>,
fn into_object(self) -> PyObjectRef
Source§impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
impl<T, U> OverflowingInto<U> for Twhere
U: OverflowingFrom<T>,
fn overflowing_into(self) -> (U, bool)
Source§impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
impl<T, U> RoundingInto<U> for Twhere
U: RoundingFrom<T>,
fn rounding_into(self, rm: RoundingMode) -> (U, Ordering)
Source§impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
impl<T, U> SaturatingInto<U> for Twhere
U: SaturatingFrom<T>,
fn saturating_into(self) -> U
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read moreSource§impl<T> ToDebugString for Twhere
T: Debug,
impl<T> ToDebugString for Twhere
T: Debug,
Source§fn to_debug_string(&self) -> String
fn to_debug_string(&self) -> String
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
Encode the hex strict representing
self into the result. Upper case
letters are used (e.g. F9B4CA)