Struct cpython::PyDict
[−]
[src]
pub struct PyDict(_);
Represents a Python dict
.
Methods
impl PyDict
[src]
fn new(py: Python) -> PyDict
[src]
Creates a new empty dictionary.
May panic when running out of memory.
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.
fn clear(&self, _py: Python)
[src]
Empty an existing dictionary of all key-value pairs.
fn len(&self, _py: Python) -> usize
[src]
Return the number of items in the dictionary. This is equivalent to len(p) on a dictionary.
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
.
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.
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
.
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]
.
fn items_list(&self, py: Python) -> PyList
[src]
fn items(&self, py: Python) -> Vec<(PyObject, PyObject)>
[src]
Returns the list of (key,value) pairs in this dictionary.
Trait Implementations
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]
Converts self into a Python object.
fn into_py_object(self, _py: Python) -> PyDict
[src]
Converts self into a Python object. Read more
fn with_borrowed_ptr<F, R>(&self, _py: Python, f: F) -> R where
F: FnOnce(*mut PyObject) -> R,
[src]
F: FnOnce(*mut PyObject) -> R,
Converts self into a Python object and calls the specified closure on the native FFI pointer underlying the Python object. Read more
impl<'source> FromPyObject<'source> for PyDict
[src]
fn extract(py: Python, obj: &'source PyObject) -> PyResult<PyDict>
[src]
Extracts Self
from the source PyObject
.
impl<'source> FromPyObject<'source> for &'source PyDict
[src]
fn extract(py: Python, obj: &'source PyObject) -> PyResult<&'source PyDict>
[src]
Extracts Self
from the source PyObject
.
impl PythonObject for PyDict
[src]
fn as_object(&self) -> &PyObject
[src]
Casts the Python object to PyObject.
fn into_object(self) -> PyObject
[src]
Casts the Python object to PyObject.
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>>
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>>
[src]
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
Cast from PyObject to a concrete Python object type.
impl PythonObjectWithTypeObject for PyDict
[src]
fn type_object(py: Python) -> PyType
[src]
Retrieves the type object for this Python object type.