Struct PyDict

Source
pub struct PyDict<K>
where K: Eq + Hash + PyDictKey,
{ /* private fields */ }

Implementations§

Source§

impl<K> PyDict<K>
where K: Eq + Hash + PyDictKey,

Source

pub fn new() -> PyDict<K>

Creates an empty PyDict.

Source

pub fn insert<V>(&mut self, k: K, v: V) -> Option<V>
where PyArg: From<V>, V: From<PyArg>,

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.

Source

pub fn remove<V>(&mut self, k: &K) -> Option<V>
where V: From<PyArg>,

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.

Source

pub fn get<'a, V>(&'a self, k: &K) -> Option<&'a V>
where PyArg: AsRef<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.

Source

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) };
Source

pub fn into_raw(self) -> *mut size_t

Returns self as raw pointer. Use this method when returning a PyDict to Python.

Source

pub fn into_hashmap<V>(self) -> HashMap<K, V>
where V: From<PyArg>,

Consumes self and returns a HashMap, takes one type parameter and transforms inner content to that type.

Source

pub fn speciallized_iter<V: From<PyArg>>(self) -> IntoIter<K, V>

Consume self and turn it into an iterator.

Trait Implementations§

Source§

impl<K> AsRef<PyDict<K>> for PyArg
where K: Eq + Hash + PyDictKey,

Source§

fn as_ref(&self) -> &PyDict<K>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<K> Clone for PyDict<K>
where K: Eq + Hash + PyDictKey + Clone,

Source§

fn clone(&self) -> PyDict<K>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<K> Debug for PyDict<K>
where K: Eq + Hash + PyDictKey + Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<K> Default for PyDict<K>
where K: Eq + Hash + PyDictKey + Default,

Source§

fn default() -> PyDict<K>

Returns the “default value” for a type. Read more
Source§

impl<K, V> From<HashMap<K, V>> for PyDict<K>
where K: PyDictKey + Eq + Hash, PyArg: From<V>,

Source§

fn from(hm: HashMap<K, V>) -> PyDict<K>

Converts to this type from the input type.
Source§

impl<K> From<PyArg> for PyDict<K>
where K: Eq + Hash + PyDictKey,

Source§

fn from(a: PyArg) -> PyDict<K>

Converts to this type from the input type.
Source§

impl<K> From<PyDict<K>> for PyArg
where K: Eq + Hash + PyDictKey,

Source§

fn from(a: PyDict<K>) -> PyArg

Converts to this type from the input type.
Source§

impl<K, V> FromIterator<(K, V)> for PyDict<K>
where K: PyDictKey + Eq + Hash, PyArg: From<V>,

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<K> PartialEq for PyDict<K>
where K: Eq + Hash + PyDictKey + PartialEq,

Source§

fn eq(&self, other: &PyDict<K>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<K> StructuralPartialEq for PyDict<K>
where K: Eq + Hash + PyDictKey,

Auto Trait Implementations§

§

impl<K> Freeze for PyDict<K>

§

impl<K> RefUnwindSafe for PyDict<K>
where K: RefUnwindSafe,

§

impl<K> !Send for PyDict<K>

§

impl<K> !Sync for PyDict<K>

§

impl<K> Unpin for PyDict<K>
where K: Unpin,

§

impl<K> UnwindSafe for PyDict<K>
where K: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.