Enum lace_codebook::ValueMap
source · pub enum ValueMap {
String(CategoryMap<String>),
U8(usize),
Bool,
}Variants§
Implementations§
source§impl ValueMap
impl ValueMap
pub fn new<T>(cats: BTreeSet<T>) -> Selfwhere Self: From<BTreeSet<T>>,
pub fn len(&self) -> usize
pub fn is_empty(&self) -> bool
sourcepub fn ix(&self, cat: &Category) -> Option<usize>
pub fn ix(&self, cat: &Category) -> Option<usize>
Get the usize index of the category if it exists
Examples
let mut cats: BTreeSet<String> = BTreeSet::new();
cats.insert("B".into());
cats.insert("C".into());
cats.insert("A".into());
let value_map = ValueMap::new(cats);
assert_eq!(value_map.ix(&Category::String("A".into())), Some(0));
assert_eq!(value_map.ix(&Category::String("B".into())), Some(1));
assert_eq!(value_map.ix(&Category::String("C".into())), Some(2));
assert_eq!(value_map.ix(&Category::String("D".into())), None);sourcepub fn category(&self, ix: usize) -> Category
pub fn category(&self, ix: usize) -> Category
Get the category associated with an index
Examples
let mut cats: BTreeSet<String> = BTreeSet::new();
cats.insert("B".into());
cats.insert("C".into());
cats.insert("A".into());
let value_map = ValueMap::new(cats);
assert_eq!(value_map.category(0), Category::String("A".into()));
assert_eq!(value_map.category(1), Category::String("B".into()));
assert_eq!(value_map.category(2), Category::String("C".into()));pub fn contains_cat(&self, cat: &Category) -> bool
pub fn iter(&self) -> CategoryIter<'_> ⓘ
sourcepub fn is_extended(&self, other: &Self) -> bool
pub fn is_extended(&self, other: &Self) -> bool
Determine whether a value map is an extended version of this value map
Examples
use std::collections::BTreeSet;
use lace_data::Category;
let mut cats: BTreeSet<String> = BTreeSet::new();
cats.insert("B".into());
cats.insert("C".into());
cats.insert("A".into());
let value_map_1 = ValueMap::new(cats.clone());
assert!(value_map_1.is_extended(&value_map_1));
cats.insert("D".into());
let value_map_2 = ValueMap::new(cats);
assert!(value_map_1.len() < value_map_2.len());
assert!(value_map_1.is_extended(&value_map_2));
assert!(!value_map_2.is_extended(&value_map_1));Integer valuemap
let value_map_1 = ValueMap::U8(2);
let value_map_2 = ValueMap::U8(3);
let value_map_3 = ValueMap::U8(4);
assert!(value_map_1.is_extended(&value_map_1));
assert!(value_map_1.is_extended(&value_map_2));
assert!(value_map_1.is_extended(&value_map_3));
assert!(!value_map_2.is_extended(&value_map_1));
assert!(value_map_2.is_extended(&value_map_2));
assert!(value_map_2.is_extended(&value_map_3));
assert!(!value_map_3.is_extended(&value_map_1));
assert!(!value_map_3.is_extended(&value_map_2));
assert!(value_map_3.is_extended(&value_map_3));let value_map = ValueMap::Bool;
assert!(value_map.is_extended(&value_map));Trait Implementations§
source§impl<'de> Deserialize<'de> for ValueMap
impl<'de> Deserialize<'de> for ValueMap
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl PartialEq<ValueMap> for ValueMap
impl PartialEq<ValueMap> for ValueMap
impl Eq for ValueMap
impl StructuralEq for ValueMap
impl StructuralPartialEq for ValueMap
Auto Trait Implementations§
impl RefUnwindSafe for ValueMap
impl Send for ValueMap
impl Sync for ValueMap
impl Unpin for ValueMap
impl UnwindSafe for ValueMap
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Checks if this value is equivalent to the given key. Read more
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.§impl<T> Pointable for T
impl<T> Pointable for T
§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere SS: SubsetOf<SP>,
§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
The inverse inclusion map: attempts to construct
self from the equivalent element of its
superset. Read more§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
Checks if
self is actually part of its subset T (and can be converted to it).§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
Use with care! Same as
self.to_subset but without any property checks. Always succeeds.§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.