Struct cpython::PyDict [−][src]
Represents a Python dict
.
Implementations
impl PyDict
[src]
pub fn new(py: Python<'_>) -> PyDict
[src]
Creates a new empty dictionary.
May panic when running out of memory.
pub fn copy(&self, py: Python<'_>) -> PyResult<PyDict>
[src]
Return a new dictionary that contains the same key-value pairs as self.
Corresponds to dict(self)
in Python.
pub fn clear(&self, _py: Python<'_>)
[src]
Empty an existing dictionary of all key-value pairs.
pub fn len(&self, _py: Python<'_>) -> usize
[src]
Return the number of items in the dictionary. This is equivalent to len(p) on a dictionary.
pub fn contains<K>(&self, py: Python<'_>, key: K) -> PyResult<bool> where
K: ToPyObject,
[src]
K: ToPyObject,
Determine if the dictionary contains the specified key.
This is equivalent to the Python expression key in self
.
pub fn get_item<K>(&self, py: Python<'_>, key: K) -> Option<PyObject> where
K: ToPyObject,
[src]
K: ToPyObject,
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,
[src]
K: ToPyObject,
V: ToPyObject,
Sets an item value.
This is equivalent to the Python expression self[key] = value
.
pub fn del_item<K>(&self, py: Python<'_>, key: K) -> PyResult<()> where
K: ToPyObject,
[src]
K: ToPyObject,
Deletes an item.
This is equivalent to the Python expression del self[key]
.
pub fn items_list(&self, py: Python<'_>) -> PyList
[src]
pub fn items(&self, py: Python<'_>) -> Vec<(PyObject, PyObject)>
[src]
Returns the list of (key,value) pairs in this dictionary.
Trait Implementations
impl<'s> FromPyObject<'s> for PyDict
[src]
impl<'s> FromPyObject<'s> for &'s PyDict
[src]
impl PythonObject for PyDict
[src]
fn as_object(&self) -> &PyObject
[src]
fn into_object(self) -> PyObject
[src]
unsafe fn unchecked_downcast_from(obj: PyObject) -> Self
[src]
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
unsafe fn unchecked_downcast_borrow_from<'a>(obj: &'a PyObject) -> &'a Self
[src]
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
impl PythonObjectWithCheckedDowncast for PyDict
[src]
fn downcast_from<'p>(
py: Python<'p>,
obj: PyObject
) -> Result<PyDict, PythonObjectDowncastError<'p>>
[src]
py: Python<'p>,
obj: PyObject
) -> Result<PyDict, PythonObjectDowncastError<'p>>
fn downcast_borrow_from<'a, 'p>(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
[src]
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
impl PythonObjectWithTypeObject for PyDict
[src]
fn type_object(py: Python<'_>) -> PyType
[src]
impl ToPyObject for PyDict
[src]
Identity conversion: allows using existing PyObject
instances where
T: ToPyObject
is expected.
type ObjectType = PyDict
fn to_py_object(&self, py: Python<'_>) -> PyDict
[src]
fn into_py_object(self, _py: Python<'_>) -> PyDict
[src]
fn with_borrowed_ptr<F, R>(&self, _py: Python<'_>, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
Auto Trait Implementations
impl RefUnwindSafe for PyDict
[src]
impl Send for PyDict
[src]
impl Sync for PyDict
[src]
impl Unpin for PyDict
[src]
impl UnwindSafe for PyDict
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,