Struct open_ai::PyDict
[−]
[src]
pub struct PyDict(_);
Represents a Python dict
.
Methods
impl PyDict
[src]
fn new(py: Python) -> PyDict
Creates a new empty dictionary.
May panic when running out of memory.
fn copy(&self, py: Python) -> Result<PyDict, PyErr>
Return a new dictionary that contains the same key-value pairs as self.
Corresponds to dict(self)
in Python.
fn clear(&self, _py: Python)
Empty an existing dictionary of all key-value pairs.
fn len(&self, _py: Python) -> usize
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) -> Result<bool, PyErr> where
K: ToPyObject,
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,
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) -> Result<(), PyErr> where
K: ToPyObject,
V: ToPyObject,
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) -> Result<(), PyErr> where
K: ToPyObject,
K: ToPyObject,
Deletes an item.
This is equivalent to the Python expression del self[key]
.
fn items_list(&self, py: Python) -> PyList
fn items(&self, py: Python) -> Vec<(PyObject, PyObject)>
Returns the list of (key,value) pairs in this dictionary.
Trait Implementations
impl PythonObjectWithTypeObject for PyDict
[src]
fn type_object(py: Python) -> PyType
impl PythonObjectWithCheckedDowncast for PyDict
[src]
fn downcast_from(
py: Python<'p>,
obj: PyObject
) -> Result<PyDict, PythonObjectDowncastError<'p>>
py: Python<'p>,
obj: PyObject
) -> Result<PyDict, PythonObjectDowncastError<'p>>
fn downcast_borrow_from(
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
py: Python<'p>,
obj: &'a PyObject
) -> Result<&'a PyDict, PythonObjectDowncastError<'p>>
impl PythonObject for PyDict
[src]
fn as_object(&self) -> &PyObject
fn into_object(self) -> PyObject
unsafe fn unchecked_downcast_from(obj: PyObject) -> PyDict
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
unsafe fn unchecked_downcast_borrow_from(obj: &'a PyObject) -> &'a PyDict
Unchecked downcast from PyObject to Self. Undefined behavior if the input object does not have the expected type.
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
Converts self into a Python object.
fn into_py_object(self, _py: Python) -> PyDict
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,
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