pub enum ValueMap {
String(CategoryMap<String>),
U8(usize),
Bool,
}Variants§
Implementations§
Source§impl ValueMap
impl ValueMap
pub fn new<T>(cats: BTreeSet<T>) -> ValueMap
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: &ValueMap) -> bool
pub fn is_extended(&self, other: &ValueMap) -> 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));Sourcepub fn extend(
&mut self,
extension: ValueMapExtension,
) -> Result<(), ValueMapExtensionError>
pub fn extend( &mut self, extension: ValueMapExtension, ) -> Result<(), ValueMapExtensionError>
Extend this ValueMap
Trait Implementations§
Source§impl<'de> Deserialize<'de> for ValueMap
impl<'de> Deserialize<'de> for ValueMap
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ValueMap, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ValueMap, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for ValueMap
impl Serialize for ValueMap
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl Eq for ValueMap
impl StructuralPartialEq for ValueMap
Auto Trait Implementations§
impl Freeze for ValueMap
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§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 moreSource§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).Source§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.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
The inclusion map: converts
self to the equivalent element of its superset.