pub struct PyDict<K>{ /* private fields */ }
Implementations§
Source§impl<K> PyDict<K>
impl<K> PyDict<K>
Sourcepub fn insert<V>(&mut self, k: K, v: V) -> Option<V>
pub fn insert<V>(&mut self, k: K, v: V) -> Option<V>
Inserts a key-value pair into the map.
If the map did not have this key present, None is returned.
If the map did have this key present, the value is updated, and the old value is returned. The key is not updated, though; this matters for types that can be == without being identical. See the module-level documentation for more.
Sourcepub fn remove<V>(&mut self, k: &K) -> Option<V>
pub fn remove<V>(&mut self, k: &K) -> Option<V>
Removes a key from the map, returning the value at the key if the key was previously in the map.
The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.
Sourcepub fn get<'a, V>(&'a self, k: &K) -> Option<&'a V>
pub fn get<'a, V>(&'a self, k: &K) -> Option<&'a V>
Returns a reference to the value corresponding to the key.
The key may be any borrowed form of the map’s key type, but Hash and Eq on the borrowed form must match those for the key type.
Sourcepub unsafe fn from_ptr(ptr: *mut size_t) -> PyDict<K>
pub unsafe fn from_ptr(ptr: *mut size_t) -> PyDict<K>
Get a PyDict from a previously boxed PyDict.
Takes the key as type parameter K
, the raw pointer to the dictionary as argument
and returns a PyDict with key type K
(check
PyArg variants for allowed key types).
let dict = unsafe { PyDict::<u64>::from_ptr(dict) };
Sourcepub fn into_raw(self) -> *mut size_t
pub fn into_raw(self) -> *mut size_t
Returns self as raw pointer. Use this method when returning a PyDict to Python.
Sourcepub fn into_hashmap<V>(self) -> HashMap<K, V>
pub fn into_hashmap<V>(self) -> HashMap<K, V>
Consumes self and returns a HashMap, takes one type parameter and transforms inner content to that type.