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
pub trait OptionExt<T>
{
fn has<U>(&self, value: U) -> bool
where U: PartialEq<T>;
}
impl<T> OptionExt<T> for Option<T>
{
fn has<U>(&self, x: U) -> bool
where U: PartialEq<T>
{
match self {
Some(y) => x == *y,
None => false,
}
}
}
#[cfg(test)]
mod tests
{
use std::path::Component;
use super::*;
#[test]
fn test_has()
{
assert!(Some(Component::ParentDir).has(Component::ParentDir));
assert_eq!(Some(Component::ParentDir).has(Component::ParentDir), true);
assert_eq!(None.has(Component::ParentDir), false);
}
}