pub struct PyDict { /* private fields */ }Implementations§
Source§impl PyDict
impl PyDict
pub fn new_ref(ctx: &Context) -> PyRef<Self>
👎Deprecated:
use PyDict::default().into_ref() instead
Sourcepub fn keys_vec(&self) -> Vec<PyObjectRef>
pub fn keys_vec(&self) -> Vec<PyObjectRef>
Returns all keys as a Vec, atomically under a single read lock. Thread-safe: prevents “dictionary changed size during iteration” errors.
Sourcepub fn values_vec(&self) -> Vec<PyObjectRef>
pub fn values_vec(&self) -> Vec<PyObjectRef>
Returns all values as a Vec, atomically under a single read lock. Thread-safe: prevents “dictionary changed size during iteration” errors.
Sourcepub fn items_vec(&self) -> Vec<(PyObjectRef, PyObjectRef)>
pub fn items_vec(&self) -> Vec<(PyObjectRef, PyObjectRef)>
Returns all items as a Vec, atomically under a single read lock. Thread-safe: prevents “dictionary changed size during iteration” errors.
pub fn merge_object( &self, other: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()>
pub fn merge_object_if_missing( &self, other: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()>
pub fn merge_from_seq2( &self, seq2: &PyObject, override_existing: bool, vm: &VirtualMachine, ) -> PyResult<()>
pub fn is_empty(&self) -> bool
Sourcepub fn inner_setitem<K: DictKey + ?Sized>(
&self,
key: &K,
value: PyObjectRef,
vm: &VirtualMachine,
) -> PyResult<()>
pub fn inner_setitem<K: DictKey + ?Sized>( &self, key: &K, value: PyObjectRef, vm: &VirtualMachine, ) -> PyResult<()>
Set item variant which can be called with multiple key types, such as str to name a notable one.
pub fn get_or_insert( &self, vm: &VirtualMachine, key: &PyObject, default: impl FnOnce() -> PyObjectRef, ) -> PyResult
pub fn from_attributes( attrs: IndexMap<&'static PyStrInterned, PyObjectRef, RandomState>, vm: &VirtualMachine, ) -> PyResult<Self>
pub fn contains_key<K: DictKey + ?Sized>( &self, key: &K, vm: &VirtualMachine, ) -> bool
pub fn size(&self) -> DictSize
pub fn next_entry( &self, position: usize, ) -> Option<(usize, PyObjectRef, PyObjectRef)>
pub fn inner_getitem_opt<K: DictKey + ?Sized>( &self, key: &K, vm: &VirtualMachine, ) -> PyResult<Option<PyObjectRef>>
Trait Implementations§
Source§impl AsMapping for PyDict
impl AsMapping for PyDict
fn as_mapping() -> &'static PyMappingMethods
fn mapping_downcast(mapping: PyMapping<'_>) -> &Py<Self>
fn extend_slots(slots: &mut PyTypeSlots)
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl AsNumber for PyDict
impl AsNumber for PyDict
fn as_number() -> &'static PyNumberMethods
fn extend_slots(slots: &mut PyTypeSlots)
fn clone_exact(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyRef<Self>
fn number_downcast(num: PyNumber<'_>) -> &Py<Self>
fn number_downcast_exact(num: PyNumber<'_>, vm: &VirtualMachine) -> PyRef<Self>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl AsSequence for PyDict
impl AsSequence for PyDict
fn as_sequence() -> &'static PySequenceMethods
fn sequence_downcast(seq: PySequence<'_>) -> &Py<Self>
fn extend_slots(slots: &mut PyTypeSlots)
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl Comparable for PyDict
impl Comparable for PyDict
fn cmp( zelf: &Py<Self>, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, ) -> PyResult<PyComparisonValue>
fn slot_richcompare( zelf: &PyObject, other: &PyObject, op: PyComparisonOp, vm: &VirtualMachine, ) -> PyResult<Either<PyObjectRef, PyComparisonValue>>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl DefaultConstructor for PyDict
impl DefaultConstructor for PyDict
fn construct_and_init(
args: Self::Args,
vm: &VirtualMachine,
) -> PyResult<PyRef<Self>>where
Self: Initializer,
Source§impl Initializer for PyDict
impl Initializer for PyDict
type Args = (OptionalArg, KwArgs)
fn init( zelf: &Py<Self>, (dict_obj, kwargs): Self::Args, vm: &VirtualMachine, ) -> PyResult<()>
fn slot_init( zelf: &PyObject, args: FuncArgs, vm: &VirtualMachine, ) -> PyResult<()>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl Iterable for PyDict
impl Iterable for PyDict
fn iter(zelf: PyRef<Self>, vm: &VirtualMachine) -> PyResult
fn slot_iter(zelf: PyObjectRef, vm: &VirtualMachine) -> PyResult
fn extend_slots(_slots: &mut PyTypeSlots)
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl MaybeTraverse for PyDict
impl MaybeTraverse for PyDict
Source§const HAS_TRAVERSE: bool = true
const HAS_TRAVERSE: bool = true
if is traceable, will be used by vtable to determine
Source§const HAS_CLEAR: bool = true
const HAS_CLEAR: bool = true
if has clear implementation for circular reference resolution (tp_clear)
fn try_traverse(&self, tracer_fn: &mut TraverseFn<'_>)
fn try_clear(&mut self, out: &mut Vec<PyObjectRef>)
Source§impl PyClassDef for PyDict
impl PyClassDef for PyDict
const NAME: &'static str = "dict"
const MODULE_NAME: Option<&'static str> = None
const TP_NAME: &'static str = "dict"
const DOC: ItemDoc
Source§const ATTR_DOCS: &'static [(&'static str, u32, u32)]
const ATTR_DOCS: &'static [(&'static str, u32, u32)]
Attribute name → database span, sorted by name.
(u32::MAX, 0) is an explicit empty doc.const BASICSIZE: usize
const UNHASHABLE: bool = true
const MEMBERS: &'static [PyMemberSpec]
type Base = PyBaseObject
fn assert_member_layout()
const ITEMSIZE: usize = 0
Source§impl PyClassImpl for PyDict
impl PyClassImpl for PyDict
const TP_FLAGS: PyTypeFlags
Source§const INTERNAL_DOC: ItemDoc
const INTERNAL_DOC: ItemDoc
Signature-bearing class doc.
ItemDoc::NONE when the constructor has no signature.const METHOD_DEFS: &'static [PyMethodDef]
fn impl_extend_class(ctx: &'static Context, class: &'static Py<PyType>)
fn extend_slots(slots: &mut PyTypeSlots)
fn extend_class(ctx: &'static Context, class: &'static Py<PyType>)where
Self: Sized,
fn make_static_type() -> PyTypeRefwhere
Self: StaticType + Sized,
fn make_slots() -> PyTypeSlots
Source§impl PyPayload for PyDict
impl PyPayload for PyDict
Source§const MAX_FREELIST: usize = 80
const MAX_FREELIST: usize = 80
Maximum number of objects to keep in the freelist.
Source§const HAS_FREELIST: bool = true
const HAS_FREELIST: bool = true
Whether this type has a freelist. Types with freelists require
immediate (non-deferred) GC untracking during dealloc to prevent
race conditions when the object is reused.
fn class(ctx: &Context) -> &'static Py<PyType>
Source§unsafe fn freelist_push(obj: *mut PyObject) -> bool
unsafe fn freelist_push(obj: *mut PyObject) -> bool
Try to push a dead object onto this type’s freelist for reuse.
Returns true if the object was stored (caller must NOT free the memory).
Called after tp_clear, so the payload is a cleared husk; implementations
must not rely on its pre-clear contents. Read more
Source§unsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>>
unsafe fn freelist_pop(_payload: &Self) -> Option<NonNull<PyObject>>
Try to pop a pre-allocated object from this type’s freelist.
The returned pointer still has the old payload; the caller must
reinitialize
ref_count, gc_bits, and payload. Read moreconst PAYLOAD_TYPE_ID: TypeId = _
fn try_downcast_from(obj: &PyObject, vm: &VirtualMachine) -> PyResult<()>
Source§const NEW_REF_UNTRACKED: bool = false
const NEW_REF_UNTRACKED: bool = false
Whether
PyRef::new_ref skips auto-tracking this type in the GC even
when it would otherwise qualify (has traverse, dict, or heap type).
Such objects are created untracked and must be tracked explicitly if
and when they can become part of a reference cycle. Used by FrameObject,
which is created untracked and tracked lazily only on escape.fn into_pyobject(self, vm: &VirtualMachine) -> PyObjectRefwhere
Self: Debug,
fn _into_ref(self, cls: PyTypeRef, ctx: &Context) -> PyRef<Self>where
Self: Debug,
fn into_exact_ref(self, ctx: &Context) -> PyRefExact<Self>where
Self: Debug,
fn into_ref(self, ctx: &Context) -> PyRef<Self>where
Self: Debug,
fn into_ref_with_type(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
Source§fn into_ref_with_type_lazy_dict(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
fn into_ref_with_type_lazy_dict(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
) -> PyResult<PyRef<Self>>where
Self: Debug,
Like
into_ref_with_type, but leaves the instance __dict__ unallocated
until the first attribute write or __dict__ access. Only valid for types
whose attribute protocol materializes the dict lazily via get_or_insert.fn into_ref_with_type_and_dict(
self,
vm: &VirtualMachine,
cls: PyTypeRef,
eager_dict: bool,
) -> PyResult<PyRef<Self>>where
Self: Debug,
Source§impl Representable for PyDict
impl Representable for PyDict
fn repr(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<PyStrRef>
fn repr_str(_zelf: &Py<Self>, _vm: &VirtualMachine) -> PyResult<String>
fn slot_repr(zelf: &PyObject, vm: &VirtualMachine) -> PyResult<PyRef<PyStr>>
fn repr_wtf8(zelf: &Py<Self>, vm: &VirtualMachine) -> PyResult<Wtf8Buf>
const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
Source§impl StaticType for PyDict
impl StaticType for PyDict
fn static_cell() -> &'static StaticCell<PyTypeRef>
fn static_metaclass() -> &'static Py<PyType>
fn static_baseclass() -> &'static Py<PyType>
fn static_type() -> &'static Py<PyType>
fn init_manually(typ: PyTypeRef) -> &'static Py<PyType>
fn init_builtin_type() -> &'static Py<PyType>where
Self: PyClassImpl,
fn create_static_type() -> PyTypeRefwhere
Self: PyClassImpl,
Source§impl Traverse for PyDict
impl Traverse for PyDict
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.
Auto Trait Implementations§
impl !Freeze for PyDict
impl !RefUnwindSafe for PyDict
impl !Send for PyDict
impl !Sync for PyDict
impl !UnwindSafe for PyDict
impl Unpin for PyDict
impl UnsafeUnpin for PyDict
Blanket Implementations§
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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Constructor for Twhere
T: DefaultConstructor,
impl<T> Constructor for Twhere
T: DefaultConstructor,
type Args = FuncArgs
Source§fn slot_new(
cls: PyRef<PyType>,
_args: FuncArgs,
vm: &VirtualMachine,
) -> Result<PyObjectRef, PyRef<PyBaseException>>
fn slot_new( cls: PyRef<PyType>, _args: FuncArgs, vm: &VirtualMachine, ) -> Result<PyObjectRef, PyRef<PyBaseException>>
The type slot for
__new__. Override this only when you need special
behavior beyond simple payload creation.Source§fn py_new(
cls: &Py<PyType>,
_args: <T as Constructor>::Args,
vm: &VirtualMachine,
) -> Result<T, PyRef<PyBaseException>>
fn py_new( cls: &Py<PyType>, _args: <T as Constructor>::Args, vm: &VirtualMachine, ) -> Result<T, PyRef<PyBaseException>>
Creates the payload for this type. In most cases, just implement this method
and let the default
slot_new handle wrapping with the correct type.Source§const DROP_KWARGS_WHEN_INIT_OVERRIDDEN: bool = false
const DROP_KWARGS_WHEN_INIT_OVERRIDDEN: bool = false
When true, extra keywords are dropped if a subclass replaced
tp_init.const __OWN_METHOD_DEFS: &'static [PyMethodDef] = _
fn __extend_py_class(ctx: &'static Context, class: &'static Py<PyType>)
fn __extend_slots(slots: &mut PyTypeSlots)
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> ⓘ
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 more