CIndexMap

Struct CIndexMap 

Source
pub struct CIndexMap<K, V> { /* private fields */ }

Implementations§

Source§

impl<K, V> CIndexMap<K, V>

Source

pub fn new() -> CIndexMap<K, V>

Constructs a new CIndexMap.

§Panics

When size_of::<K> or size_of::<T> is 0.

Source

pub fn insert(&mut self, key: K, value: V) -> Result<()>

Inserts a new key/value pair into the map.

This function returns Ok(()) if the key/value pair was inserted successfully.

Source

pub fn remove(&mut self, index: usize) -> Result<()>

Removes an element at the specified index.

Source

pub fn index(&self, index: usize) -> Result<&K>

Returns the key to the entry at the specified index.

Use CIndexMap::get to get the value of the entry based off of the key.

Source

pub fn get_no_peq(&self, key: K) -> Option<&V>

Gets the value associated with the specified key.

This function is preferred for when the underlying Key/Value types for this map cannot, for some reason, implement PartialEq.

This performs a raw memory comparison between the supplied value and the keys in the current map. This comparison doesn’t work on a lot of dynamically sized types, like String and Vec.

§Correct usage
use x_map::maps::CIndexMap;
let mut map = CIndexMap::new();
map.insert("foo", "bar").unwrap();

// Prints `map.get("foo").unwrap() = "bar"`
dbg!(map.get("foo").unwrap());

// Prints `map.get_no_peq("foo").unwrap() = "bar"`
dbg!(map.get_no_peq("foo").unwrap());
§Incorrect usage
use x_map::maps::CIndexMap;
let string_one = String::from("foo");
let string_two = String::from("bar");

let mut map = CIndexMap::new();
map.insert(string_one.to_string(), string_two.to_string()).unwrap();


// Prints `map.get(string_one.to_string()) = Some("bar")`
dbg!(map.get(string_one.to_string()));

// Prints `map.get_no_peq(string_one.to_string()) = None`
dbg!(map.get_no_peq(string_one.to_string()));
Source§

impl<K: PartialEq, V> CIndexMap<K, V>

Source

pub fn get(&self, key: K) -> Option<&V>

Gets the value associated with the specified key.

Multiple implementations exist for get:

  • When K does not implement PartialEq, get will perform bytewise comparison between the input and the map keys. This is a fallback implementation, and will not always produce expected results. This implementation will have unexpected results on dynamically sized types, such as String and Vec.

  • When K implements PartialEq, get will call PartialEq::partial_eq() for comparison between the input and the map keys. This is the preferred implementation, and will produce the expected results.

Source

pub fn contains_key(&self, key: K) -> bool

Checks if the map contains the provided key.

  • If it does, this function returns true,
  • If it does not, this function returns false.
Source§

impl<K, V: PartialEq> CIndexMap<K, V>

Source

pub fn contains_value(&self, value: V) -> bool

Checks if the map contains the provided value.

  • If it does, this function returns true,
  • If it does not, this function returns false.

Trait Implementations§

Source§

impl<K: Debug, V: Debug> Debug for CIndexMap<K, V>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<K, V> Freeze for CIndexMap<K, V>

§

impl<K, V> RefUnwindSafe for CIndexMap<K, V>

§

impl<K, V> !Send for CIndexMap<K, V>

§

impl<K, V> !Sync for CIndexMap<K, V>

§

impl<K, V> Unpin for CIndexMap<K, V>

§

impl<K, V> UnwindSafe for CIndexMap<K, V>

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> 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, 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.