Struct rustpython_vm::object::PyRef
source · #[repr(transparent)]pub struct PyRef<T: PyObjectPayload> { /* 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 concat_in_place(&mut self, other: &str, vm: &VirtualMachine)
source§impl PyRef<PyTraceback>
impl PyRef<PyTraceback>
pub fn iter(&self) -> impl Iterator<Item = PyRef<PyTraceback>>
source§impl<T: PyObjectPayload> PyRef<T>
impl<T: PyObjectPayload> 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>>§
sourcepub fn to_attributes(
&self,
vm: &VirtualMachine
) -> IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>
pub fn to_attributes( &self, vm: &VirtualMachine ) -> IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>
Take a python dictionary and convert it to attributes.
pub fn get_item_opt<K: DictKey + ?Sized>( &self, key: &K, vm: &VirtualMachine ) -> PyResult<Option<PyObjectRef>>
pub fn get_item<K: DictKey + ?Sized>( &self, key: &K, vm: &VirtualMachine ) -> PyResult
pub fn set_item<K: DictKey + ?Sized>( &self, key: &K, value: PyObjectRef, vm: &VirtualMachine ) -> PyResult<()>
pub fn del_item<K: DictKey + ?Sized>( &self, key: &K, vm: &VirtualMachine ) -> PyResult<()>
pub fn get_chain<K: DictKey + ?Sized>( &self, other: &Self, key: &K, vm: &VirtualMachine ) -> PyResult<Option<PyObjectRef>>
pub fn f_back(&self, vm: &VirtualMachine) -> Option<PyRef<Frame>>
pub fn __init_methods(&self, vm: &VirtualMachine) -> PyResult<()>
pub fn dict(&self) -> PyDictRef
pub fn get_attr<'a>( &self, attr_name: impl AsPyStr<'a>, vm: &VirtualMachine ) -> PyResult
pub fn set_attr<'a>( &self, attr_name: impl AsPyStr<'a>, attr_value: impl Into<PyObjectRef>, vm: &VirtualMachine ) -> PyResult<()>
sourcepub fn fast_issubclass(&self, cls: &impl Borrow<PyObject>) -> bool
pub fn fast_issubclass(&self, cls: &impl Borrow<PyObject>) -> bool
Determines if subclass
is actually a subclass of cls
, this doesn’t call subclasscheck,
so only use this if cls
is known to have not overridden the base subclasscheck magic
method.
pub fn iter_mro( &self ) -> impl Iterator<Item = &Py<PyType>> + DoubleEndedIterator
pub fn iter_base_chain(&self) -> impl Iterator<Item = &Py<PyType>>
pub fn extend_methods( &'static self, method_defs: &'static [PyMethodDef], ctx: &Context )
pub fn run(&self, vm: &VirtualMachine) -> PyResult<ExecutionResult>
pub fn yield_from_target(&self) -> Option<PyObjectRef>
pub fn is_internal_frame(&self) -> bool
pub fn next_external_frame(&self, vm: &VirtualMachine) -> Option<FrameRef>
pub fn build_function(&self, vm: &VirtualMachine) -> PyRef<PyNativeFunction>
pub fn build_method( &self, class: &'static Py<PyType>, vm: &VirtualMachine ) -> PyRef<PyMethodDescriptor>
pub fn upgrade(&self) -> Option<PyObjectRef>
pub fn downgrade( &self, callback: Option<PyObjectRef>, vm: &VirtualMachine ) -> PyResult<PyWeakRef<T>>
Trait Implementations§
source§impl<T: PyObjectPayload> Clone for PyRef<T>
impl<T: PyObjectPayload> Clone for PyRef<T>
source§impl<T: PyObjectPayload> Debug for PyRef<T>
impl<T: PyObjectPayload> Debug for PyRef<T>
source§impl<T> Deref for PyRef<T>where
T: PyObjectPayload,
impl<T> Deref for PyRef<T>where T: PyObjectPayload,
source§impl<T: PyObjectPayload> Drop for PyRef<T>
impl<T: PyObjectPayload> Drop for PyRef<T>
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: PyObjectPayload> From<PyRef<T>> for PyAtomicRef<T>
impl<T: PyObjectPayload> From<PyRef<T>> for PyAtomicRef<T>
source§impl<T> From<PyRef<T>> for PyObjectRefwhere
T: PyObjectPayload,
impl<T> From<PyRef<T>> for PyObjectRefwhere T: PyObjectPayload,
source§impl<T: PyObjectPayload> ToPyObject for PyRef<T>
impl<T: PyObjectPayload> 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§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.
Auto Trait Implementations§
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> !UnwindSafe for PyRef<T>
Blanket Implementations§
source§impl<T> AsObject for Twhere
T: Borrow<PyObject>,
impl<T> AsObject for Twhere T: Borrow<PyObject>,
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
§impl<T, U> ExactFrom<T> for Uwhere
U: TryFrom<T>,
impl<T, U> ExactFrom<T> for Uwhere U: TryFrom<T>,
fn exact_from(value: T) -> U
§impl<T, U> ExactInto<U> for Twhere
U: ExactFrom<T>,
impl<T, U> ExactInto<U> for Twhere U: ExactFrom<T>,
fn exact_into(self) -> U
source§impl<T> FromArgOptional for Twhere
T: TryFromObject,
impl<T> FromArgOptional for Twhere T: TryFromObject,
type Inner = T
fn from_inner(x: T) -> T
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> IntoObject for Twhere
T: Into<PyObjectRef>,
impl<T> IntoObject for Twhere T: Into<PyObjectRef>,
fn into_object(self) -> PyObjectRef
§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)
§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
§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
§impl<T> ToDebugString for Twhere
T: Debug,
impl<T> ToDebugString for Twhere T: Debug,
§fn to_debug_string(&self) -> String
fn to_debug_string(&self) -> String
source§impl<T> ToHex for Twhere
T: AsRef<[u8]>,
impl<T> ToHex for Twhere T: AsRef<[u8]>,
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
)