Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 1b5b577

Browse files
committed
feat: Add From<&str> implementation for Token
1 parent d3731dd commit 1b5b577

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

filter-parser/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,13 @@ impl<'a> From<Span<'a>> for Token<'a> {
115115
}
116116
}
117117

118+
/// Allow [Token] to be constructed from &[str]
119+
impl<'a> From<&'a str> for Token<'a> {
120+
fn from(s: &'a str) -> Self {
121+
Token::from(Span::new_extra(s, s))
122+
}
123+
}
124+
118125
#[derive(Debug, Clone, PartialEq, Eq)]
119126
pub enum FilterCondition<'a> {
120127
Not(Box<Self>),
@@ -664,6 +671,13 @@ pub mod tests {
664671
assert!(filter.token_at_depth(2).is_some());
665672
assert!(filter.token_at_depth(3).is_none());
666673
}
674+
675+
#[test]
676+
fn token_from_str() {
677+
let s = "test string that should not be parsed";
678+
let token: Token = s.into();
679+
assert_eq!(token.value(), s);
680+
}
667681
}
668682

669683
impl<'a> std::fmt::Display for FilterCondition<'a> {

0 commit comments

Comments
 (0)