aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/either.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-04-10 08:12:54 +0100
committerAleksey Kladov <[email protected]>2019-04-10 08:12:54 +0100
commit1cd184d6539478c7e54c92835902921976dce5d1 (patch)
tree3b6e19f4556f85c2875ae3e6376f35fe3f34d17a /crates/ra_hir/src/either.rs
parentb863272899a1bae63c7d9411d0ebff74652bae8e (diff)
use either for uses
Diffstat (limited to 'crates/ra_hir/src/either.rs')
-rw-r--r--crates/ra_hir/src/either.rs18
1 files changed, 18 insertions, 0 deletions
diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs
new file mode 100644
index 000000000..6714529d9
--- /dev/null
+++ b/crates/ra_hir/src/either.rs
@@ -0,0 +1,18 @@
1#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
2pub enum Either<A, B> {
3 A(A),
4 B(B),
5}
6
7impl<A, B> Either<A, B> {
8 pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V>
9 where
10 F1: FnOnce(A) -> U,
11 F2: FnOnce(B) -> V,
12 {
13 match self {
14 Either::A(a) => Either::A(f1(a)),
15 Either::B(b) => Either::B(f2(b)),
16 }
17 }
18}