pub struct PyDict(_);
Expand description
Represents a Python dict
.
Implementations
sourceimpl PyDict
impl PyDict
sourcepub fn new(py: Python<'_>) -> PyDict
pub fn new(py: Python<'_>) -> PyDict
Creates a new empty dictionary.
May panic when running out of memory.
sourcepub fn copy(&self, py: Python<'_>) -> PyResult<PyDict>
pub fn copy(&self, py: Python<'_>) -> PyResult<PyDict>
Return a new dictionary that contains the same key-value pairs as self.
Corresponds to dict(self)
in Python.
sourcepub fn len(&self, _py: Python<'_>) -> usize
pub fn len(&self, _py: Python<'_>) -> usize
Return the number of items in the dictionary. This is equivalent to len(p) on a dictionary.
sourcepub fn contains<K>(&self, py: Python<'_>, key: K) -> PyResult<bool>where
K: ToPyObject,
pub fn contains<K>(&self, py: Python<'_>, key: K) -> PyResult<bool>where
K: ToPyObject,
Determine if the dictionary contains the specified key.
This is equivalent to the Python expression key in self
.
sourcepub fn get_item<K>(&self, py: Python<'_>, key: K) -> Option<PyObject>where
K: ToPyObject,
pub fn get_item<K>(&self, py: Python<'_>, key: K) -> Option<PyObject>where
K: ToPyObject,
Gets an item from the dictionary. Returns None if the item is not present, or if an error occurs.
sourcepub fn set_item<K, V>(&self, py: Python<'_>, key: K, value: V) -> PyResult<()>where
K: ToPyObject,
V: ToPyObject,
pub fn set_item<K, V>(&self, py: Python<'_>, key: K, value: V) -> PyResult<()>where
K: ToPyObject,
V: ToPyObject,
Sets an item value.
This is equivalent to the Python expression self[key] = value
.
sourcepub fn del_item<K>(&self, py: Python<'_>, key: K) -> PyResult<()>where
K: ToPyObject,
pub fn del_item<K>(&self, py: Python<'_>, key: K) -> PyResult<()>where
K: ToPyObject,
Deletes an item.
This is equivalent to the Python expression del self[key]
.
pub fn items_list(&self, py: Python<'_>) -> PyList
Trait Implementations
sourceimpl<'s> FromPyObject<'s> for &'s PyDict
impl<'s> FromPyObject<'s> for &'s PyDict
sourceimpl<'s> FromPyObject<'s> for PyDict
impl<'s> FromPyObject<'s> for PyDict
sourceimpl PythonObject for PyDict
impl PythonObject for PyDict
sourceunsafe fn unchecked_downcast_from(obj: PyObject) -> Self
unsafe fn unchecked_downcast_from(obj: PyObject) -> Self
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
sourceunsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self
unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
sourcefn into_object(self) -> PyObject
fn into_object(self) -> PyObject
sourceimpl PythonObjectWithCheckedDowncast for PyDict
impl PythonObjectWithCheckedDowncast for PyDict
sourcefn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyDict, PythonObjectDowncastError<'p>>
fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyDict, PythonObjectDowncastError<'p>>
sourcefn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
sourceimpl PythonObjectWithTypeObject for PyDict
impl PythonObjectWithTypeObject for PyDict
sourcefn type_object(py: Python<'_>) -> PyType
fn type_object(py: Python<'_>) -> PyType
sourceimpl ToPyObject for PyDict
impl ToPyObject for PyDict
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.