diff --git a/filter-parser/src/lib.rs b/filter-parser/src/lib.rs index a9bd9b3d7..61801e3d4 100644 --- a/filter-parser/src/lib.rs +++ b/filter-parser/src/lib.rs @@ -115,6 +115,13 @@ impl<'a> From> 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), @@ -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> {