Struct cpython::PyDict[][src]

pub struct PyDict(_);

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]

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]

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]

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]

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]

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]

impl PythonObjectWithTypeObject for PyDict[src]

impl ToPyObject for PyDict[src]

Identity conversion: allows using existing PyObject instances where T: ToPyObject is expected.

type ObjectType = PyDict

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.