-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmatcher.rs
More file actions
56 lines (47 loc) · 1.12 KB
/
matcher.rs
File metadata and controls
56 lines (47 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
extern crate alloc;
use alloc::boxed::Box;
use rdf_model::Term;
use crate::variable::Variable;
pub enum Matcher {
Variable(Variable),
Term(Box<dyn Term>),
}
impl Matcher {
pub fn as_variable(&self) -> Option<&Variable> {
match self {
Self::Variable(var) => Some(var),
_ => None,
}
}
}
impl PartialEq<&dyn Term> for Matcher {
fn eq(&self, term: &&dyn Term) -> bool {
match self {
Self::Variable(_) => true,
Self::Term(t) => t.as_str() == term.as_str(),
}
}
}
impl From<Variable> for Matcher {
fn from(var: Variable) -> Self {
Self::Variable(var)
}
}
impl From<&str> for Matcher {
fn from(name: &str) -> Self {
name.into()
}
}
impl From<Box<dyn Term>> for Matcher {
fn from(term: Box<dyn Term>) -> Self {
Self::Term(term)
}
}
impl core::fmt::Debug for Matcher {
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
match self {
Self::Variable(var) => write!(f, "{:?}", var),
Self::Term(t) => f.write_str(&t.as_str()),
}
}
}