mod matrix;
mod set;
use derive_more::{AsMut, AsRef, Deref, DerefMut};
use serde::{Deserialize, Serialize};
use std::fmt::{Display, Formatter};
pub(crate) use self::matrix::Matrix as FeatureMatrix;
pub(crate) use self::set::Set as FeatureSet;
#[derive(
Clone,
Debug,
Ord,
PartialOrd,
Eq,
PartialEq,
Hash,
Deref,
DerefMut,
AsRef,
AsMut,
Serialize,
Deserialize,
)]
#[serde(transparent)]
#[as_ref(forward)]
#[as_mut(forward)]
pub(crate) struct Feature(pub(crate) String);
impl Display for Feature {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
Display::fmt(&self.0, f)
}
}
impl From<String> for Feature {
fn from(s: String) -> Self {
Feature(s)
}
}
impl From<&String> for Feature {
fn from(s: &String) -> Self {
Feature(s.clone())
}
}
impl From<&str> for Feature {
fn from(s: &str) -> Self {
Feature(s.to_string())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn feature_display() {
assert_eq!(format!("{}", Feature::from("foo")), "foo");
}
#[test]
fn feature_from_string() {
let f = Feature::from(String::from("bar"));
assert_eq!(*f, "bar");
}
#[test]
fn feature_from_str_ref() {
let s = String::from("baz");
let f = Feature::from(&s);
assert_eq!(*f, "baz");
}
}