aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_expand/src/either.rs
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-03 16:13:42 +0000
committerGitHub <[email protected]>2019-12-03 16:13:42 +0000
commit96b9d5b44ed50160c7a4eb07a31bee5f05b1ecf3 (patch)
tree74a889d70e201d6997c6baf179261ab3ed8bf23c /crates/ra_hir_expand/src/either.rs
parent15f143f0c33cbd382a2ad7a407d9601cb843d164 (diff)
parent009437f5d9949d2276aa26040e03af0ab328acf3 (diff)
Merge #2469
2469: Replace `ra_hir_expand::either` with crate r=matklad a=ice1000 As title. Co-authored-by: ice1000 <[email protected]>
Diffstat (limited to 'crates/ra_hir_expand/src/either.rs')
-rw-r--r--crates/ra_hir_expand/src/either.rs54
1 files changed, 0 insertions, 54 deletions
diff --git a/crates/ra_hir_expand/src/either.rs b/crates/ra_hir_expand/src/either.rs
deleted file mode 100644
index 83583ef8b..000000000
--- a/crates/ra_hir_expand/src/either.rs
+++ /dev/null
@@ -1,54 +0,0 @@
1//! FIXME: write short doc here
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}