feat: Add From<&str> implementation for Token

This commit is contained in:
Gregory Conrad 2022-12-03 13:13:41 -05:00
parent d3731dda48
commit 1b5b5778c1

View File

@ -115,6 +115,13 @@ impl<'a> From<Span<'a>> for Token<'a> {
}
}
/// Allow [Token] to be constructed from &[str]
impl<'a> From<&'a str> for Token<'a> {
fn from(s: &'a str) -> Self {
Token::from(Span::new_extra(s, s))
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum FilterCondition<'a> {
Not(Box<Self>),
@ -664,6 +671,13 @@ pub mod tests {
assert!(filter.token_at_depth(2).is_some());
assert!(filter.token_at_depth(3).is_none());
}
#[test]
fn token_from_str() {
let s = "test string that should not be parsed";
let token: Token = s.into();
assert_eq!(token.value(), s);
}
}
impl<'a> std::fmt::Display for FilterCondition<'a> {