pub struct PyDict(/* private fields */);
Expand description
Represents a Python dict
.
Implementations§
Source§impl 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§
Source§impl<'s> FromPyObject<'s> for &'s PyDict
impl<'s> FromPyObject<'s> for &'s PyDict
Source§impl<'s> FromPyObject<'s> for PyDict
impl<'s> FromPyObject<'s> for PyDict
Source§impl PythonObject for PyDict
impl PythonObject for PyDict
Source§unsafe 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.
Source§unsafe 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.
Source§fn into_object(self) -> PyObject
fn into_object(self) -> PyObject
Source§impl PythonObjectWithCheckedDowncast for PyDict
impl PythonObjectWithCheckedDowncast for PyDict
Source§fn 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>>
Source§fn 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>>
Source§impl PythonObjectWithTypeObject for PyDict
impl PythonObjectWithTypeObject for PyDict
Source§fn type_object(py: Python<'_>) -> PyType
fn type_object(py: Python<'_>) -> PyType
Source§impl ToPyObject for PyDict
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.
impl ToPyObject for PyDict
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.