aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/either.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-10-30 13:12:55 +0000
committerAleksey Kladov <[email protected]>2019-10-30 14:43:11 +0000
commit16e620c052016010b2f17070a98bdc1e7e849ab3 (patch)
treea00ec9181595cea9e340da3ead490348ff7b1666 /crates/ra_hir/src/either.rs
parentf996b6019bd2f388bd9994ea83f25487eb111560 (diff)
move raw_items to hir_def
Diffstat (limited to 'crates/ra_hir/src/either.rs')
-rw-r--r--crates/ra_hir/src/either.rs55
1 files changed, 1 insertions, 54 deletions
diff --git a/crates/ra_hir/src/either.rs b/crates/ra_hir/src/either.rs
index 83583ef8b..44498dd38 100644
--- a/crates/ra_hir/src/either.rs
+++ b/crates/ra_hir/src/either.rs
@@ -1,54 +1 @@
1//! FIXME: write short doc here pub use hir_def::either::*;
2
3#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
4pub enum Either<A, B> {
5 A(A),
6 B(B),
7}
8
9impl<A, B> Either<A, B> {
10 pub fn either<R, F1, F2>(self, f1: F1, f2: F2) -> R
11 where
12 F1: FnOnce(A) -> R,
13 F2: FnOnce(B) -> R,
14 {
15 match self {
16 Either::A(a) => f1(a),
17 Either::B(b) => f2(b),
18 }
19 }
20 pub fn map<U, V, F1, F2>(self, f1: F1, f2: F2) -> Either<U, V>
21 where
22 F1: FnOnce(A) -> U,
23 F2: FnOnce(B) -> V,
24 {
25 match self {
26 Either::A(a) => Either::A(f1(a)),
27 Either::B(b) => Either::B(f2(b)),
28 }
29 }
30 pub fn map_a<U, F>(self, f: F) -> Either<U, B>
31 where
32 F: FnOnce(A) -> U,
33 {
34 self.map(f, |it| it)
35 }
36 pub fn a(self) -> Option<A> {
37 match self {
38 Either::A(it) => Some(it),
39 Either::B(_) => None,
40 }
41 }
42 pub fn b(self) -> Option<B> {
43 match self {
44 Either::A(_) => None,
45 Either::B(it) => Some(it),
46 }
47 }
48 pub fn as_ref(&self) -> Either<&A, &B> {
49 match self {
50 Either::A(it) => Either::A(it),
51 Either::B(it) => Either::B(it),
52 }
53 }
54}