pub struct Py<T> { /* private fields */ }Expand description
This is an actual python object. It consists of a typ which is the
python class, and carries some rust payload optionally. This rust
payload can be a rust float or rust int in case of float and int objects.
Implementations§
Source§impl Py<PyByteArray>
impl Py<PyByteArray>
Source§impl Py<PyCode>
impl Py<PyCode>
pub fn co_cellvars(&self, vm: &VirtualMachine) -> PyTupleRef
pub fn co_varnames(&self, vm: &VirtualMachine) -> PyTupleRef
pub fn co_code(&self, vm: &VirtualMachine) -> PyBytesRef
pub fn _co_code_adaptive(&self, vm: &VirtualMachine) -> PyBytesRef
pub fn co_freevars(&self, vm: &VirtualMachine) -> PyTupleRef
pub fn co_linetable(&self, vm: &VirtualMachine) -> PyBytesRef
pub fn co_exceptiontable(&self, vm: &VirtualMachine) -> PyBytesRef
pub fn co_lines(&self, vm: &VirtualMachine) -> PyResult<PyObjectRef>
pub fn co_positions(&self, vm: &VirtualMachine) -> PyResult<PyObjectRef>
pub fn co_branches(&self, vm: &VirtualMachine) -> PyResult<PyObjectRef>
pub fn __replace__( &self, args: ReplaceArgs, vm: &VirtualMachine, ) -> PyResult<PyCode>
pub fn replace( &self, args: ReplaceArgs, vm: &VirtualMachine, ) -> PyResult<PyCode>
Source§impl Py<PyDict>
impl Py<PyDict>
Sourcepub fn to_attributes(
&self,
vm: &VirtualMachine,
on_non_string: impl FnOnce(&VirtualMachine) -> PyResult<()>,
) -> PyResult<IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>>
pub fn to_attributes( &self, vm: &VirtualMachine, on_non_string: impl FnOnce(&VirtualMachine) -> PyResult<()>, ) -> PyResult<IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>>
Take a python dictionary and convert it to attributes.
PyAttributes is keyed by interned strings, so a key that is not a
string has nowhere to go. Those keys are left out, and on_non_string
is called once, the first time one turns up, so the caller can decide
whether that deserves an error or a warning.
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 pop_item<K: DictKey + ?Sized>( &self, key: &K, vm: &VirtualMachine, ) -> PyResult<Option<PyObjectRef>>
pub fn get_chain<K: DictKey + ?Sized>( &self, other: &Self, key: &K, vm: &VirtualMachine, ) -> PyResult<Option<PyObjectRef>>
Source§impl Py<FrameObject>
impl Py<FrameObject>
pub fn f_locals(&self, vm: &VirtualMachine) -> PyResult
pub fn f_back(&self, vm: &VirtualMachine) -> Option<PyRef<FrameObject>>
pub fn f_globals(&self) -> PyDictRef
pub fn f_builtins(&self) -> PyObjectRef
pub fn f_code(&self) -> PyRef<PyCode>
Source§impl Py<PyFunction>
impl Py<PyFunction>
pub fn invoke_with_locals( &self, func_args: FuncArgs, locals: Option<ArgMapping>, vm: &VirtualMachine, ) -> PyResult
pub fn invoke(&self, func_args: FuncArgs, vm: &VirtualMachine) -> PyResult
Sourcepub fn func_version(&self) -> u32
pub fn func_version(&self) -> u32
Returns the function version, or 0 if invalidated.
Sourcepub fn get_version_for_current_state(&self) -> u32
pub fn get_version_for_current_state(&self) -> u32
Returns the current version, assigning a fresh one if previously invalidated.
Returns 0 if the version counter has overflowed.
_PyFunction_GetVersionForCurrentState
Sourcepub fn invoke_exact_args(
&self,
args: Vec<PyObjectRef>,
vm: &VirtualMachine,
) -> PyResult
pub fn invoke_exact_args( &self, args: Vec<PyObjectRef>, vm: &VirtualMachine, ) -> PyResult
Fast path for calling a simple function with exact positional args. Skips FuncArgs allocation, prepend_arg, and fill_locals_from_args. Only valid when: CO_OPTIMIZED, no VARARGS, no VARKEYWORDS, no kwonlyargs, and nargs == co_argcount.
Source§impl Py<PyInt>
impl Py<PyInt>
pub const fn as_bigint(&self) -> &BigInt
Sourcepub fn to_str_radix_10(&self) -> String
pub fn to_str_radix_10(&self) -> String
Fast decimal string conversion, using i64 path when possible.
pub fn as_u32_mask(&self) -> u32
pub fn as_u64_mask(&self) -> u64
pub fn try_to_primitive<I>(&self, vm: &VirtualMachine) -> PyResult<I>
pub fn try_to_primitive_in_range<I>(&self, vm: &VirtualMachine) -> PyResult<I>
Source§impl Py<PyList>
impl Py<PyList>
pub fn borrow_vec(&self) -> PyMappedRwLockReadGuard<'_, [PyObjectRef]>
pub fn borrow_vec_mut(&self) -> PyRwLockWriteGuard<'_, Vec<PyObjectRef>>
Source§impl Py<PyMappingProxy>
impl Py<PyMappingProxy>
pub fn items(&self, vm: &VirtualMachine) -> PyResult
pub fn keys(&self, vm: &VirtualMachine) -> PyResult
pub fn values(&self, vm: &VirtualMachine) -> PyResult
pub fn copy(&self, vm: &VirtualMachine) -> PyResult
Source§impl Py<PyModule>
impl Py<PyModule>
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<()>
Source§impl Py<PyStr>
impl Py<PyStr>
pub fn isascii(&self) -> bool
pub fn partition(&self, sep: PyStrRef, vm: &VirtualMachine) -> PyResult
pub fn rpartition(&self, sep: PyStrRef, vm: &VirtualMachine) -> PyResult
pub fn isidentifier(&self) -> bool
pub fn translate( &self, table: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<Wtf8Buf>
Source§impl Py<PyType>
impl Py<PyType>
pub fn slots(&self) -> &PyTypeSlots
pub fn attributes(&self) -> &TypeNamespace
pub fn tp_version_tag(&self) -> &AtomicU32
pub fn heaptype_ext(&self) -> Option<&HeapTypeExt>
pub fn is_subtype(&self, other: &Self) -> bool
Sourcepub fn check_exact<'a>(
obj: &'a PyObject,
vm: &VirtualMachine,
) -> Option<&'a Self>
pub fn check_exact<'a>( obj: &'a PyObject, vm: &VirtualMachine, ) -> Option<&'a Self>
Equivalent to CPython’s PyType_CheckExact macro Checks if obj is exactly a type (not a subclass)
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 mro_map_collect<F, R>(&self, f: F) -> Vec<R>where
F: Fn(&Self) -> R,
pub fn mro_collect(&self) -> Vec<PyRef<PyType>>
pub fn iter_base_chain(&self) -> impl Iterator<Item = &Self>
pub fn extend_methods( &'static self, method_defs: &'static [PyMethodDef], ctx: &Context, )
Source§impl Py<PyType>
impl Py<PyType>
pub fn __name__(&self, vm: &VirtualMachine) -> PyStrRef
pub fn __qualname__(&self, vm: &VirtualMachine) -> PyObjectRef
pub fn __module__(&self, vm: &VirtualMachine) -> PyResult<PyObjectRef>
Source§impl Py<PySet>
impl Py<PySet>
pub fn add(&self, object: PyObjectRef, vm: &VirtualMachine) -> PyResult<()>
pub fn discard(&self, object: PyObjectRef, vm: &VirtualMachine) -> PyResult<()>
pub fn clear(&self)
pub fn pop(&self, vm: &VirtualMachine) -> PyResult
Source§impl Py<PySlice>
impl Py<PySlice>
pub fn to_saturated(&self, vm: &VirtualMachine) -> PyResult<SaturatedSlice>
Source§impl Py<PyTuple>
impl Py<PyTuple>
pub fn extract_tuple<'a, T: FromPyTuple<'a>>( &'a self, vm: &VirtualMachine, ) -> PyResult<T>
Source§impl Py<PyBaseException>
impl Py<PyBaseException>
pub fn traceback(&self) -> Option<PyRef<PyTraceback>>
pub fn add_note(&self, note: PyStrRef, vm: &VirtualMachine) -> PyResult<()>
pub fn args(&self) -> PyTupleRef
pub fn __traceback__(&self) -> Option<PyRef<PyTraceback>>
pub fn __cause__(&self) -> Option<PyRef<PyBaseException>>
pub fn __context__(&self) -> Option<PyRef<PyBaseException>>
Source§impl Py<FrameObject>
impl Py<FrameObject>
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<FrameObjectRef>
Source§impl Py<HeapMethodDef>
impl Py<HeapMethodDef>
pub fn build_function( &self, vm: &VirtualMachine, zelf: Option<PyObjectRef>, ) -> PyRef<PyNativeFunction>
pub fn build_method( &self, class: &'static Py<PyType>, vm: &VirtualMachine, ) -> PyRef<PyMethodDescriptor>
Source§impl<T: PyPayload> Py<T>
impl<T: PyPayload> Py<T>
pub fn downgrade( &self, callback: Option<PyObjectRef>, vm: &VirtualMachine, ) -> PyResult<PyWeakRef<T>>
pub fn payload(&self) -> &T
Source§impl<T: PySubclass> Py<T>
impl<T: PySubclass> Py<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§
impl<T> Eq for Py<T>
Source§impl<'a> IntoIterator for &'a Py<PyDict>
impl<'a> IntoIterator for &'a Py<PyDict>
Source§impl<'a, R> IntoIterator for &'a Py<PyTuple<R>>
impl<'a, R> IntoIterator for &'a Py<PyTuple<R>>
Source§impl<T> ToOwned for Py<T>
impl<T> ToOwned for Py<T>
Source§impl Traverse for Py<Erased>
impl Traverse for Py<Erased>
Source§fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
Because PyObject hold a Py<Erased>, so we need to trace it
Source§fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
Source§impl<T: MaybeTraverse> Traverse for Py<T>
impl<T: MaybeTraverse> Traverse for Py<T>
Source§fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
fn traverse(&self, tracer_fn: &mut TraverseFn<'_>)
DO notice that call trace on Py<T> means apply tracer_fn on Py<T>’s children,
not like call trace on PyRef<T> which apply tracer_fn on PyRef<T> itself
Type is known, so we can call try_trace directly instead of using erased type vtable
Source§fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
fn clear(&mut self, _out: &mut Vec<PyObjectRef>)
Source§impl<'a, T: PyPayload> TryFromBorrowedObject<'a> for &'a Py<T>
impl<'a, T: PyPayload> TryFromBorrowedObject<'a> for &'a Py<T>
Source§fn try_from_borrowed_object(
vm: &VirtualMachine,
obj: &'a PyObject,
) -> PyResult<Self>
fn try_from_borrowed_object( vm: &VirtualMachine, obj: &'a PyObject, ) -> PyResult<Self>
Auto Trait Implementations§
impl<T> !Freeze for Py<T>
impl<T> !RefUnwindSafe for Py<T>
impl<T> !Send for Py<T>
impl<T> !Sync for Py<T>
impl<T> !Unpin for Py<T>
impl<T> !UnsafeUnpin for Py<T>
impl<T> !UnwindSafe for Py<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
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§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
key and return true if they are equal.impl<T> ErasedDestructor for Twhere
T: 'static,
impl<T> Helper for T
Source§impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
impl<T, U> ImaginaryInto<U> for Twhere
U: ImaginaryFrom<T>,
fn imaginary_into(self) -> U
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> ⓘ
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> ⓘ
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, 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> PrimitiveIntRandomBounds for T
impl<T> PrimitiveSignedRandomBounds for T
impl<T> PyThreadingConstraint for T
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
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> ToCharString for Twhere
T: Display,
impl<T> ToCharString for Twhere
T: Display,
Source§fn try_to_char_string(&self) -> Result<CharString, ToCharStringError>
fn try_to_char_string(&self) -> Result<CharString, ToCharStringError>
CharString. Read moreSource§fn to_char_string(&self) -> CharString
fn to_char_string(&self) -> CharString
CharString. Read moreSource§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>
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
CompactString. Read more