Struct cpython::PyDict [−][src]
pub struct PyDict(_);
Expand description
Represents a Python dict
.
Implementations
Creates a new empty dictionary.
May panic when running out of memory.
Return a new dictionary that contains the same key-value pairs as self.
Corresponds to dict(self)
in Python.
Return the number of items in the dictionary. This is equivalent to len(p) on a dictionary.
Determine if the dictionary contains the specified key.
This is equivalent to the Python expression key in self
.
Gets an item from the dictionary. Returns None if the item is not present, or if an error occurs.
pub 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
.
Deletes an item.
This is equivalent to the Python expression del self[key]
.
Trait Implementations
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
Casts the Python object to PyObject.
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>>
Cast from PyObject to a concrete Python object type.
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>>
Cast from PyObject to a concrete Python object type.
Retrieves the type object for this Python object type.
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.
type ObjectType = PyDict
Converts self into a Python object.
Converts self into a Python object. Read more