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

Add more members of filter_parser to milli:: & From<&str> implementation for Token #719

Merged
merged 2 commits into from
Dec 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions filter-parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>),
Expand Down Expand Up @@ -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> {
Expand Down
2 changes: 1 addition & 1 deletion milli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use std::collections::{BTreeMap, HashMap};
use std::convert::{TryFrom, TryInto};
use std::hash::BuildHasherDefault;

pub use filter_parser::{Condition, FilterCondition};
pub use filter_parser::{Condition, FilterCondition, Span, Token};
use fxhash::{FxHasher32, FxHasher64};
pub use grenad::CompressionType;
use serde_json::Value;
Expand Down