Enum LeveledHashMapError

Source
pub enum LeveledHashMapError<K> {
    KeyTooMany,
    KeyNotExist {
        level: usize,
        key: Arc<K>,
    },
    KeyChainEmpty,
    KeyChainIncorrect {
        level: usize,
        key: Arc<K>,
        last_key: Option<Arc<K>>,
    },
}
Expand description

Possible errors come from LeveledHashMap.

Variants§

§

KeyTooMany

The length of a key chain is over the max level of a LeveledHashMap.

use std::sync::Arc;

use leveled_hash_map::{LeveledHashMap, LeveledHashMapError};

let mut map = LeveledHashMap::new();

map.insert(&[Arc::new("food")], 100).unwrap();

// now the map has "Level 0", "Level 0" is available to be got, "Level 0" and "Level 1" are available to be inserted

assert_eq!(&100, map.get_advanced(&[Arc::new("food")], 0).unwrap());

// try to get value at "Level 1"

match map.get_professional(&[Arc::new("food"), Arc::new("dessert")], 0) {
    Ok(_) => unreachable!(),
    Err(err) => match err {
        LeveledHashMapError::KeyTooMany => (),
        _ => unreachable!()
    }
}

// try to insert value to "Level 2"

match map.insert(&[Arc::new("food"), Arc::new("dessert"), Arc::new("cake")], 10) {
    Ok(_) => unreachable!(),
    Err(err) => match err {
        LeveledHashMapError::KeyTooMany => (),
        _ => unreachable!()
    }
}

// try to insert value to "Level 1"

match map.insert(&[Arc::new("food"), Arc::new("dessert")], 10) {
    Ok(_) => (),
    Err(err) => unreachable!()
}
§

KeyNotExist

The key chain is correct, but the last key in the key chain does not exist.

use std::sync::Arc;

use leveled_hash_map::{LeveledHashMap, LeveledHashMapError};

let mut map = LeveledHashMap::new();

map.insert(&[Arc::new("food")], 100).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], 100).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert"), Arc::new("cake")], 100).unwrap();

// try to get "food/dessert/chocolate"

match map.get_professional(&[Arc::new("food"), Arc::new("dessert"), Arc::new("chocolate")], 0) {
    Ok(_) => unreachable!(),
    Err(err) => {
        match err {
            LeveledHashMapError::KeyNotExist {
                level,
                key,
            } => {
                assert_eq!(2, level);
                assert_eq!(Arc::new("chocolate"), key);
            }
            _ => unreachable!(),
        }
    }
}

Fields

§level: usize
§key: Arc<K>
§

KeyChainEmpty

The key chain is empty.

use std::sync::Arc;

use leveled_hash_map::{LeveledHashMap, LeveledHashMapError};

let mut map = LeveledHashMap::new();

map.insert(&[Arc::new("food")], 100).unwrap();

// try to get ""

match map.get_professional(&[], 0) {
    Ok(_) => unreachable!(),
    Err(err) => {
        match err {
            LeveledHashMapError::KeyChainEmpty => (),
            _ => unreachable!(),
        }
    }
}
§

KeyChainIncorrect

The key chain is incorrect.

use std::sync::Arc;

use leveled_hash_map::{LeveledHashMap, LeveledHashMapError};

let mut map = LeveledHashMap::new();

map.insert(&[Arc::new("food")], 100).unwrap();

map.insert(&[Arc::new("food"), Arc::new("meat")], 200).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert")], 100).unwrap();

map.insert(&[Arc::new("food"), Arc::new("dessert"), Arc::new("cake")], 100).unwrap();

// try to get "food/meat/chocolate", here "food/meat" exists

match map.get_professional(&[Arc::new("food"), Arc::new("meat"), Arc::new("cake")], 0) {
    Ok(_) => unreachable!(),
    Err(err) => {
        match err {
            LeveledHashMapError::KeyChainIncorrect {
                level,
                key,
                last_key,
            } => {
                assert_eq!(2, level);
                assert_eq!(Arc::new("cake"), key);
                assert_eq!(Some(Arc::new("dessert")), last_key);
            }
            _ => unreachable!(),
        }
    }
}

Fields

§level: usize
§key: Arc<K>
§last_key: Option<Arc<K>>

Trait Implementations§

Source§

impl<K> Debug for LeveledHashMapError<K>

Source§

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

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

impl<K> Display for LeveledHashMapError<K>

Source§

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

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

impl<K> Error for LeveledHashMapError<K>

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl<K> Freeze for LeveledHashMapError<K>

§

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

§

impl<K> Send for LeveledHashMapError<K>
where K: Sync + Send,

§

impl<K> Sync for LeveledHashMapError<K>
where K: Sync + Send,

§

impl<K> Unpin for LeveledHashMapError<K>

§

impl<K> UnwindSafe for LeveledHashMapError<K>
where K: RefUnwindSafe,

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.