| 1 | use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#}; |
| 2 | |
| 3 | use craterust-analyzer cargo itertools 0.14.0 crate/::EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#::*; |
| 4 | |
| 5 | use eitherrust-analyzer cargo either 1.15.0 crate/::Eitherrust-analyzer cargo either 1.15.0 Either#; |
| 6 | |
| 7 | /// Value that either holds a single A or B, or both. |
| 8 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 9 | pub enum EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, B = A> { |
| 10 | /// Both values are present. |
| 11 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(A, B), |
| 12 | /// Only the left value of type `A` is present. |
| 13 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(A), |
| 14 | /// Only the right value of type `B` is present. |
| 15 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(B), |
| 16 | } |
| 17 | |
| 18 | impl<A, B> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, B> { |
| 19 | /// If `Left`, or `Both`, return true. Otherwise, return false. |
| 20 | pub fn has_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]has_left().(&self) -> bool { |
| 21 | self.as_refrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_ref().().leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 22 | } |
| 23 | |
| 24 | /// If `Right`, or `Both`, return true, otherwise, return false. |
| 25 | pub fn has_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]has_right().(&self) -> bool { |
| 26 | self.as_refrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_ref().().rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]right().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 27 | } |
| 28 | |
| 29 | /// If `Left`, return true. Otherwise, return false. |
| 30 | /// Exclusive version of [`has_left`](EitherOrBoth::has_left). |
| 31 | pub fn is_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]is_left().(&self) -> bool { |
| 32 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(_)) |
| 33 | } |
| 34 | |
| 35 | /// If `Right`, return true. Otherwise, return false. |
| 36 | /// Exclusive version of [`has_right`](EitherOrBoth::has_right). |
| 37 | pub fn is_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]is_right().(&self) -> bool { |
| 38 | matchesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/matches!!(self, Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(_)) |
| 39 | } |
| 40 | |
| 41 | /// If `Both`, return true. Otherwise, return false. |
| 42 | pub fn is_bothrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]is_both().(&self) -> bool { |
| 43 | self.as_refrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_ref().().bothrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]both().().is_somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_some().() |
| 44 | } |
| 45 | |
| 46 | /// If `Left`, or `Both`, return `Some` with the left value. Otherwise, return `None`. |
| 47 | pub fn leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<A> { |
| 48 | match self { |
| 49 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, _) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(left), |
| 50 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | /// If `Right`, or `Both`, return `Some` with the right value. Otherwise, return `None`. |
| 55 | pub fn rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]right().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<B> { |
| 56 | match self { |
| 57 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(_, right) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right), |
| 58 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | /// Return tuple of options corresponding to the left and right value respectively |
| 63 | /// |
| 64 | /// If `Left` return `(Some(..), None)`, if `Right` return `(None,Some(..))`, else return |
| 65 | /// `(Some(..),Some(..))` |
| 66 | pub fn left_and_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left_and_right().(self) -> (Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<A>, Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<B>) { |
| 67 | self.map_anyrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]map_any().(Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#).or_defaultrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]or_default().() |
| 68 | } |
| 69 | |
| 70 | /// If `Left`, return `Some` with the left value. If `Right` or `Both`, return `None`. |
| 71 | /// |
| 72 | /// # Examples |
| 73 | /// |
| 74 | /// ``` |
| 75 | /// // On the `Left` variant. |
| 76 | /// # use itertools::{EitherOrBoth, EitherOrBoth::{Left, Right, Both}}; |
| 77 | /// let x: EitherOrBoth<_, ()> = Left("bonjour"); |
| 78 | /// assert_eq!(x.just_left(), Some("bonjour")); |
| 79 | /// |
| 80 | /// // On the `Right` variant. |
| 81 | /// let x: EitherOrBoth<(), _> = Right("hola"); |
| 82 | /// assert_eq!(x.just_left(), None); |
| 83 | /// |
| 84 | /// // On the `Both` variant. |
| 85 | /// let x = Both("bonjour", "hola"); |
| 86 | /// assert_eq!(x.just_left(), None); |
| 87 | /// ``` |
| 88 | pub fn just_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]just_left().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<A> { |
| 89 | match self { |
| 90 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(left), |
| 91 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 92 | } |
| 93 | } |
| 94 | |
| 95 | /// If `Right`, return `Some` with the right value. If `Left` or `Both`, return `None`. |
| 96 | /// |
| 97 | /// # Examples |
| 98 | /// |
| 99 | /// ``` |
| 100 | /// // On the `Left` variant. |
| 101 | /// # use itertools::{EitherOrBoth::{Left, Right, Both}, EitherOrBoth}; |
| 102 | /// let x: EitherOrBoth<_, ()> = Left("auf wiedersehen"); |
| 103 | /// assert_eq!(x.just_left(), Some("auf wiedersehen")); |
| 104 | /// |
| 105 | /// // On the `Right` variant. |
| 106 | /// let x: EitherOrBoth<(), _> = Right("adios"); |
| 107 | /// assert_eq!(x.just_left(), None); |
| 108 | /// |
| 109 | /// // On the `Both` variant. |
| 110 | /// let x = Both("auf wiedersehen", "adios"); |
| 111 | /// assert_eq!(x.just_left(), None); |
| 112 | /// ``` |
| 113 | pub fn just_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]just_right().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<B> { |
| 114 | match self { |
| 115 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(right), |
| 116 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | /// If `Both`, return `Some` containing the left and right values. Otherwise, return `None`. |
| 121 | pub fn bothrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]both().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(A, B)> { |
| 122 | match self { |
| 123 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, b) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((a, b)), |
| 124 | _ => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | /// If `Left` or `Both`, return the left value. Otherwise, convert the right value and return it. |
| 129 | pub fn into_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]into_left().(self) -> A |
| 130 | where |
| 131 | B: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<A>, |
| 132 | { |
| 133 | match self { |
| 134 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, _) => a, |
| 135 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => b.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | /// If `Right` or `Both`, return the right value. Otherwise, convert the left value and return it. |
| 140 | pub fn into_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]into_right().(self) -> B |
| 141 | where |
| 142 | A: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<B>, |
| 143 | { |
| 144 | match self { |
| 145 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(_, b) => b, |
| 146 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => a.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(), |
| 147 | } |
| 148 | } |
| 149 | |
| 150 | /// Converts from `&EitherOrBoth<A, B>` to `EitherOrBoth<&A, &B>`. |
| 151 | pub fn as_refrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_ref().(&self) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<&A, &B> { |
| 152 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 153 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(ref left) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left), |
| 154 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(ref right) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right), |
| 155 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(ref left, ref right) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, right), |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | /// Converts from `&mut EitherOrBoth<A, B>` to `EitherOrBoth<&mut A, &mut B>`. |
| 160 | pub fn as_mutrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_mut().(&mut self) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<&mut A, &mut B> { |
| 161 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 162 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(ref mut left) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left), |
| 163 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(ref mut right) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right), |
| 164 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(ref mut left, ref mut right) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, right), |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | /// Converts from `&EitherOrBoth<A, B>` to `EitherOrBoth<&_, &_>` using the [`Deref`] trait. |
| 169 | pub fn as_derefrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_deref().(&self) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<&A::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target#, &B::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target#> |
| 170 | where |
| 171 | A: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, |
| 172 | B: Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, |
| 173 | { |
| 174 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self { |
| 175 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(ref left) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left), |
| 176 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(ref right) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right), |
| 177 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(ref left, ref right) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, right), |
| 178 | } |
| 179 | } |
| 180 | |
| 181 | /// Converts from `&mut EitherOrBoth<A, B>` to `EitherOrBoth<&mut _, &mut _>` using the [`DerefMut`] trait. |
| 182 | pub fn as_deref_mutrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]as_deref_mut().(&mut self) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<&mut A::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target#, &mut B::Targetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#Target#> |
| 183 | where |
| 184 | A: DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#, |
| 185 | B: DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#, |
| 186 | { |
| 187 | match *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self { |
| 188 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(ref mut left) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left), |
| 189 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(ref mut right) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right), |
| 190 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(ref mut left, ref mut right) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, right), |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | /// Convert `EitherOrBoth<A, B>` to `EitherOrBoth<B, A>`. |
| 195 | pub fn fliprust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]flip().(self) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<B, A> { |
| 196 | match self { |
| 197 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(a), |
| 198 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(b), |
| 199 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, b) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(b, a), |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /// Apply the function `f` on the value `a` in `Left(a)` or `Both(a, b)` variants. If it is |
| 204 | /// present rewrapping the result in `self`'s original variant. |
| 205 | pub fn map_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]map_left().<F, M>(self, f: F) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<M, B> |
| 206 | where |
| 207 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(A) -> M, |
| 208 | { |
| 209 | match self { |
| 210 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, b) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(f(a), b), |
| 211 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(f(a)), |
| 212 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b), |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /// Apply the function `f` on the value `b` in `Right(b)` or `Both(a, b)` variants. |
| 217 | /// If it is present rewrapping the result in `self`'s original variant. |
| 218 | pub fn map_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]map_right().<F, M>(self, f: F) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, M> |
| 219 | where |
| 220 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(B) -> M, |
| 221 | { |
| 222 | match self { |
| 223 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a), |
| 224 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(f(b)), |
| 225 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, b) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, f(b)), |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /// Apply the functions `f` and `g` on the value `a` and `b` respectively; |
| 230 | /// found in `Left(a)`, `Right(b)`, or `Both(a, b)` variants. |
| 231 | /// The Result is rewrapped `self`'s original variant. |
| 232 | pub fn map_anyrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]map_any().<F, L, G, R>(self, f: F, g: G) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<L, R> |
| 233 | where |
| 234 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(A) -> L, |
| 235 | G: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(B) -> R, |
| 236 | { |
| 237 | match self { |
| 238 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(f(a)), |
| 239 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(g(b)), |
| 240 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, b) => Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(f(a), g(b)), |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | /// Apply the function `f` on the value `a` in `Left(a)` or `Both(a, _)` variants if it is |
| 245 | /// present. |
| 246 | pub fn left_and_thenrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left_and_then().<F, L>(self, f: F) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<L, B> |
| 247 | where |
| 248 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(A) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<L, B>, |
| 249 | { |
| 250 | match self { |
| 251 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, _) => f(a), |
| 252 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b), |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | /// Apply the function `f` on the value `b` |
| 257 | /// in `Right(b)` or `Both(_, b)` variants if it is present. |
| 258 | pub fn right_and_thenrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]right_and_then().<F, R>(self, f: F) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, R> |
| 259 | where |
| 260 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(B) -> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, R>, |
| 261 | { |
| 262 | match self { |
| 263 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a), |
| 264 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(_, b) => f(b), |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | /// Returns a tuple consisting of the `l` and `r` in `Both(l, r)`, if present. |
| 269 | /// Otherwise, returns the wrapped value for the present element, and the supplied |
| 270 | /// value for the other. The first (`l`) argument is used for a missing `Left` |
| 271 | /// value. The second (`r`) argument is used for a missing `Right` value. |
| 272 | /// |
| 273 | /// Arguments passed to `or` are eagerly evaluated; if you are passing |
| 274 | /// the result of a function call, it is recommended to use [`or_else`], |
| 275 | /// which is lazily evaluated. |
| 276 | /// |
| 277 | /// [`or_else`]: EitherOrBoth::or_else |
| 278 | /// |
| 279 | /// # Examples |
| 280 | /// |
| 281 | /// ``` |
| 282 | /// # use itertools::EitherOrBoth; |
| 283 | /// assert_eq!(EitherOrBoth::Both("tree", 1).or("stone", 5), ("tree", 1)); |
| 284 | /// assert_eq!(EitherOrBoth::Left("tree").or("stone", 5), ("tree", 5)); |
| 285 | /// assert_eq!(EitherOrBoth::Right(1).or("stone", 5), ("stone", 1)); |
| 286 | /// ``` |
| 287 | pub fn orrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]or().(self, l: A, r: B) -> (A, B) { |
| 288 | match self { |
| 289 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(inner_l) => (inner_l, r), |
| 290 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(inner_r) => (l, inner_r), |
| 291 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(inner_l, inner_r) => (inner_l, inner_r), |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | /// Returns a tuple consisting of the `l` and `r` in `Both(l, r)`, if present. |
| 296 | /// Otherwise, returns the wrapped value for the present element, and the [`default`](Default::default) |
| 297 | /// for the other. |
| 298 | pub fn or_defaultrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]or_default().(self) -> (A, B) |
| 299 | where |
| 300 | A: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 301 | B: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#, |
| 302 | { |
| 303 | match self { |
| 304 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(l) => (l, B::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().()), |
| 305 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(r) => (A::defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default#default().(), r), |
| 306 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(l, r) => (l, r), |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | /// Returns a tuple consisting of the `l` and `r` in `Both(l, r)`, if present. |
| 311 | /// Otherwise, returns the wrapped value for the present element, and computes the |
| 312 | /// missing value with the supplied closure. The first argument (`l`) is used for a |
| 313 | /// missing `Left` value. The second argument (`r`) is used for a missing `Right` value. |
| 314 | /// |
| 315 | /// # Examples |
| 316 | /// |
| 317 | /// ``` |
| 318 | /// # use itertools::EitherOrBoth; |
| 319 | /// let k = 10; |
| 320 | /// assert_eq!(EitherOrBoth::Both("tree", 1).or_else(|| "stone", || 2 * k), ("tree", 1)); |
| 321 | /// assert_eq!(EitherOrBoth::Left("tree").or_else(|| "stone", || 2 * k), ("tree", 20)); |
| 322 | /// assert_eq!(EitherOrBoth::Right(1).or_else(|| "stone", || 2 * k), ("stone", 1)); |
| 323 | /// ``` |
| 324 | pub fn or_elserust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]or_else().<L: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> A, R: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> B>(self, l: L, r: R) -> (A, B) { |
| 325 | match self { |
| 326 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(inner_l) => (inner_l, r()), |
| 327 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(inner_r) => (l(), inner_r), |
| 328 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(inner_l, inner_r) => (inner_l, inner_r), |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | /// Returns a mutable reference to the left value. If the left value is not present, |
| 333 | /// it is replaced with `val`. |
| 334 | pub fn left_or_insertrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left_or_insert().(&mut self, val: A) -> &mut A { |
| 335 | self.left_or_insert_withrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left_or_insert_with().(|| val) |
| 336 | } |
| 337 | |
| 338 | /// Returns a mutable reference to the right value. If the right value is not present, |
| 339 | /// it is replaced with `val`. |
| 340 | pub fn right_or_insertrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]right_or_insert().(&mut self, val: B) -> &mut B { |
| 341 | self.right_or_insert_withrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]right_or_insert_with().(|| val) |
| 342 | } |
| 343 | |
| 344 | /// If the left value is not present, replace it the value computed by the closure `f`. |
| 345 | /// Returns a mutable reference to the now-present left value. |
| 346 | pub fn left_or_insert_withrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]left_or_insert_with().<F>(&mut self, f: F) -> &mut A |
| 347 | where |
| 348 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> A, |
| 349 | { |
| 350 | match self { |
| 351 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, _) => left, |
| 352 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(_) => self.insert_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]insert_left().(f()), |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | /// If the right value is not present, replace it the value computed by the closure `f`. |
| 357 | /// Returns a mutable reference to the now-present right value. |
| 358 | pub fn right_or_insert_withrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]right_or_insert_with().<F>(&mut self, f: F) -> &mut B |
| 359 | where |
| 360 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#() -> B, |
| 361 | { |
| 362 | match self { |
| 363 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(_, right) => right, |
| 364 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(_) => self.insert_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]insert_right().(f()), |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | /// Sets the `left` value of this instance, and returns a mutable reference to it. |
| 369 | /// Does not affect the `right` value. |
| 370 | /// |
| 371 | /// # Examples |
| 372 | /// ``` |
| 373 | /// # use itertools::{EitherOrBoth, EitherOrBoth::{Left, Right, Both}}; |
| 374 | /// |
| 375 | /// // Overwriting a pre-existing value. |
| 376 | /// let mut either: EitherOrBoth<_, ()> = Left(0_u32); |
| 377 | /// assert_eq!(*either.insert_left(69), 69); |
| 378 | /// |
| 379 | /// // Inserting a second value. |
| 380 | /// let mut either = Right("no"); |
| 381 | /// assert_eq!(*either.insert_left("yes"), "yes"); |
| 382 | /// assert_eq!(either, Both("yes", "no")); |
| 383 | /// ``` |
| 384 | pub fn insert_leftrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]insert_left().(&mut self, val: A) -> &mut A { |
| 385 | match self { |
| 386 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, _) => { |
| 387 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().left = val; |
| 388 | left |
| 389 | } |
| 390 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right) => { |
| 391 | // This is like a map in place operation. We move out of the reference, |
| 392 | // change the value, and then move back into the reference. |
| 393 | unsafe { |
| 394 | // SAFETY: We know this pointer is valid for reading since we got it from a reference. |
| 395 | let right = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(right as *mut _); |
| 396 | // SAFETY: Again, we know the pointer is valid since we got it from a reference. |
| 397 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(self as *mut _, Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(val, right)); |
| 398 | } |
| 399 | |
| 400 | if let Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, _) = self { |
| 401 | left |
| 402 | } else { |
| 403 | // SAFETY: The above pattern will always match, since we just |
| 404 | // set `self` equal to `Both`. |
| 405 | unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hint/::unreachable_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hint/unreachable_unchecked().() } |
| 406 | } |
| 407 | } |
| 408 | } |
| 409 | } |
| 410 | |
| 411 | /// Sets the `right` value of this instance, and returns a mutable reference to it. |
| 412 | /// Does not affect the `left` value. |
| 413 | /// |
| 414 | /// # Examples |
| 415 | /// ``` |
| 416 | /// # use itertools::{EitherOrBoth, EitherOrBoth::{Left, Both}}; |
| 417 | /// // Overwriting a pre-existing value. |
| 418 | /// let mut either: EitherOrBoth<_, ()> = Left(0_u32); |
| 419 | /// assert_eq!(*either.insert_left(69), 69); |
| 420 | /// |
| 421 | /// // Inserting a second value. |
| 422 | /// let mut either = Left("what's"); |
| 423 | /// assert_eq!(*either.insert_right(9 + 10), 21 - 2); |
| 424 | /// assert_eq!(either, Both("what's", 9+10)); |
| 425 | /// ``` |
| 426 | pub fn insert_rightrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]insert_right().(&mut self, val: B) -> &mut B { |
| 427 | match self { |
| 428 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(right) | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(_, right) => { |
| 429 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().right = val; |
| 430 | right |
| 431 | } |
| 432 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(left) => { |
| 433 | // This is like a map in place operation. We move out of the reference, |
| 434 | // change the value, and then move back into the reference. |
| 435 | unsafe { |
| 436 | // SAFETY: We know this pointer is valid for reading since we got it from a reference. |
| 437 | let left = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::readrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/read().(left as *mut _); |
| 438 | // SAFETY: Again, we know the pointer is valid since we got it from a reference. |
| 439 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/write().(self as *mut _, Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, val)); |
| 440 | } |
| 441 | if let Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(_, right) = self { |
| 442 | right |
| 443 | } else { |
| 444 | // SAFETY: The above pattern will always match, since we just |
| 445 | // set `self` equal to `Both`. |
| 446 | unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hint/::unreachable_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hint/unreachable_unchecked().() } |
| 447 | } |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | /// Set `self` to `Both(..)`, containing the specified left and right values, |
| 453 | /// and returns a mutable reference to those values. |
| 454 | pub fn insert_bothrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`]insert_both().(&mut self, left: A, right: B) -> (&mut A, &mut B) { |
| 455 | *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self = Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, right); |
| 456 | if let Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(left, right) = self { |
| 457 | (left, right) |
| 458 | } else { |
| 459 | // SAFETY: The above pattern will always match, since we just |
| 460 | // set `self` equal to `Both`. |
| 461 | unsafe { stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hint/::unreachable_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hint/unreachable_unchecked().() } |
| 462 | } |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | impl<T> EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<T, T> { |
| 467 | /// Return either value of left, right, or apply a function `f` to both values if both are present. |
| 468 | /// The input function has to return the same type as both Right and Left carry. |
| 469 | /// |
| 470 | /// This function can be used to preferrably extract the left resp. right value, |
| 471 | /// but fall back to the other (i.e. right resp. left) if the preferred one is not present. |
| 472 | /// |
| 473 | /// # Examples |
| 474 | /// ``` |
| 475 | /// # use itertools::EitherOrBoth; |
| 476 | /// assert_eq!(EitherOrBoth::Both(3, 7).reduce(u32::max), 7); |
| 477 | /// assert_eq!(EitherOrBoth::Left(3).reduce(u32::max), 3); |
| 478 | /// assert_eq!(EitherOrBoth::Right(7).reduce(u32::max), 7); |
| 479 | /// |
| 480 | /// // Extract the left value if present, fall back to the right otherwise. |
| 481 | /// assert_eq!(EitherOrBoth::Left("left").reduce(|l, _r| l), "left"); |
| 482 | /// assert_eq!(EitherOrBoth::Right("right").reduce(|l, _r| l), "right"); |
| 483 | /// assert_eq!(EitherOrBoth::Both("left", "right").reduce(|l, _r| l), "left"); |
| 484 | /// ``` |
| 485 | pub fn reducerust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<T>`]reduce().<F>(self, f: F) -> T |
| 486 | where |
| 487 | F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T, T) -> T, |
| 488 | { |
| 489 | match self { |
| 490 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(a) => a, |
| 491 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(b) => b, |
| 492 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(a, b) => f(a, b), |
| 493 | } |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | impl<A, B> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, B>> for Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Eitherrust-analyzer cargo either 1.15.0 Either#<A, B>> { |
| 498 | fn fromrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`Option<Either<A, B>>`][`From<EitherOrBoth<A, B>>`]from().(value: EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, B>) -> Selfrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`Option<Either<A, B>>`][`From<EitherOrBoth<A, B>>`] { |
| 499 | match value { |
| 500 | Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(l) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Eitherrust-analyzer cargo either 1.15.0 Either#::Leftrust-analyzer cargo either 1.15.0 Either#Left#(l)), |
| 501 | Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(r) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Eitherrust-analyzer cargo either 1.15.0 Either#::Rightrust-analyzer cargo either 1.15.0 Either#Right#(r)), |
| 502 | Bothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Both#(..) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, |
| 503 | } |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | impl<A, B> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Eitherrust-analyzer cargo either 1.15.0 Either#<A, B>> for EitherOrBothrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#<A, B> { |
| 508 | fn fromrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`][`From<Either<A, B>>`]from().(either: Eitherrust-analyzer cargo either 1.15.0 Either#<A, B>) -> Selfrust-analyzer cargo itertools 0.14.0 either_or_both/impl#[`EitherOrBoth<A, B>`][`From<Either<A, B>>`] { |
| 509 | match either { |
| 510 | Eitherrust-analyzer cargo either 1.15.0 Either#::Leftrust-analyzer cargo either 1.15.0 Either#Left#(l) => Leftrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Left#(l), |
| 511 | Eitherrust-analyzer cargo either 1.15.0 Either#::Rightrust-analyzer cargo either 1.15.0 Either#Right#(l) => Rightrust-analyzer cargo itertools 0.14.0 either_or_both/EitherOrBoth#Right#(l), |
| 512 | } |
| 513 | } |
| 514 | } |