in watchman/rust/watchman_client/src/expr.rs [87:175]
fn into(self) -> Value {
match self {
Self::True => "true".into(),
Self::False => "false".into(),
Self::Not(expr) => Value::Array(vec!["not".into(), (*expr).into()]),
Self::All(expr) => {
let mut expr: Vec<Value> = expr.into_iter().map(Into::into).collect();
expr.insert(0, "allof".into());
Value::Array(expr)
}
Self::Any(expr) => {
let mut expr: Vec<Value> = expr.into_iter().map(Into::into).collect();
expr.insert(0, "anyof".into());
Value::Array(expr)
}
Self::DirName(term) => {
let mut expr: Vec<Value> = vec!["dirname".into(), term.path.try_into().unwrap()];
if let Some(depth) = term.depth {
expr.push(depth.into_term("depth"));
}
expr.into()
}
Self::Empty => "empty".into(),
Self::Exists => "exists".into(),
Self::Match(term) => vec![
"match".into(),
term.glob.into(),
if term.wholename {
"wholename"
} else {
"basename"
}
.into(),
Value::Object(hashmap! {
"includedotfiles".to_string() => term.include_dot_files.into(),
"noescape".to_string() => term.no_escape.into()
}),
]
.into(),
Self::Name(term) => vec![
"name".into(),
Value::Array(
term.paths
.into_iter()
.map(|p| p.try_into().unwrap())
.collect(),
),
if term.wholename {
"wholename"
} else {
"basename"
}
.into(),
]
.into(),
Self::Pcre(term) => vec![
"pcre".into(),
term.pattern.into(),
if term.wholename {
"wholename"
} else {
"basename"
}
.into(),
]
.into(),
Self::Since(term) => match term {
SinceTerm::ObservedClock(c) => {
vec!["since".into(), c.into(), "oclock".into()].into()
}
SinceTerm::CreatedClock(c) => {
vec!["since".into(), c.into(), "cclock".into()].into()
}
SinceTerm::MTime(c) => {
vec!["since".into(), c.to_string().into(), "mtime".into()].into()
}
SinceTerm::CTime(c) => {
vec!["since".into(), c.to_string().into(), "ctime".into()].into()
}
},
Self::Size(term) => term.into_term("size"),
Self::Suffix(term) => vec![
"suffix".into(),
Value::Array(term.into_iter().map(|p| p.try_into().unwrap()).collect()),
]
.into(),
Self::FileType(term) => vec!["type".into(), term.to_string().into()].into(),
}
}