sophia_api/prefix/
_trait.rsuse super::*;
use std::borrow::Borrow;
pub trait IsPrefix: Borrow<str> {}
pub trait AsPrefix {
fn as_prefix(&self) -> Prefix<&str>;
}
impl<T: IsPrefix> AsPrefix for T {
fn as_prefix(&self) -> Prefix<&str> {
Prefix::new_unchecked(self.borrow())
}
}
#[cfg(test)]
#[allow(clippy::unused_unit)] mod test {
use super::*;
use test_case::test_case;
#[test_case(""; "empty")]
#[test_case("a")]
#[test_case("foo")]
#[test_case("é.hê"; "with dot and accents")]
fn valid_prefix(p: &str) {
assert!(is_valid_prefix(p));
assert!(Prefix::new(p).is_ok());
}
#[test_case(" "; "space")]
#[test_case("1a")]
#[test_case("a."; "ending with dot")]
fn invalid_prefix(p: &str) {
assert!(!is_valid_prefix(p));
assert!(Prefix::new(p).is_err());
}
}