pub enum Concern<S, M> {
Success(S),
Mistake(M),
}
Expand description
Concern
is a type that can represent a Success
, or Mistake
.
NOTE: This type will become a type alias once !
is stabilized.
See the module documentation for more usage details.
Variants
Success(S)
Contains the success value
Mistake(M)
Contains the mistake value
Implementations
sourceimpl<S, M> Concern<S, M>
impl<S, M> Concern<S, M>
sourcepub fn as_ref(&self) -> Concern<&S, &M>
pub fn as_ref(&self) -> Concern<&S, &M>
Converts from &Concern<S, M>
to Concern<&S, &M>
.
Produces a new Concern
, containing a reference into the original,
leaving it in place.
Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.as_ref(), Concern::Success(&42));
let x: Concern<u32, i32> = Concern::Mistake(47);
assert_eq!(x.as_ref(), Concern::Mistake(&47));
sourcepub fn as_mut(&mut self) -> Concern<&mut S, &mut M>
pub fn as_mut(&mut self) -> Concern<&mut S, &mut M>
Converts from &mut Concern<S, M>
to Concern<&mut S, &mut F>
Examples
fn mutate(c: &mut Concern<u32, i32>) {
match c.as_mut() {
Concern::Success(s) => *s = 47,
Concern::Mistake(m) => *m = 19,
}
}
let mut x: Concern<u32, i32> = Concern::Success(42);
mutate(&mut x);
assert_eq!(x.unwrap(), 47);
let mut x: Concern<u32, i32> = Concern::Mistake(47);
mutate(&mut x);
assert_eq!(x.unwrap_mistake(), 19);
sourcepub fn iter(&self) -> Iter<'_, S>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;
pub fn iter(&self) -> Iter<'_, S>ⓘNotable traits for Iter<'a, T>impl<'a, T> Iterator for Iter<'a, T> type Item = &'a T;
Returns an iterator over the possibly contained value.
The iterator yields one value if the outcome is Success
, otherwise
none.
Examples
Basic usage:
let x: Concern<u32, i32> = Concern::Success(42);
assert_eq!(x.iter().next(), Some(&42));
let x: Concern<u32, i32> = Concern::Mistake(47);
assert_eq!(x.iter().next(), None);
sourcepub fn iter_mut(&mut self) -> IterMut<'_, S>ⓘNotable traits for IterMut<'a, T>impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
pub fn iter_mut(&mut self) -> IterMut<'_, S>ⓘNotable traits for IterMut<'a, T>impl<'a, T> Iterator for IterMut<'a, T> type Item = &'a mut T;
sourcepub fn is_success(&self) -> bool
pub fn is_success(&self) -> bool
sourcepub fn is_mistake(&self) -> bool
pub fn is_mistake(&self) -> bool
sourcepub fn success(self) -> Option<S>
pub fn success(self) -> Option<S>
Converts from Concern<S, M>
to Option<S>
Converts self
into an Option<S>
, consuming self
, and discarding
the mistake, if any.
Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.success(), Some(42));
let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.success(), None);
sourcepub fn mistake(self) -> Option<M>
pub fn mistake(self) -> Option<M>
Converts from Concern<S, M>
to Option<M>
Converts self
into an Option<M>
, consuming self
, and discarding
the success, if any.
Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.mistake(), None);
let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.mistake(), Some("hello"));
sourcepub fn map<T, C>(self, callable: C) -> Concern<T, M> where
C: FnOnce(S) -> T,
pub fn map<T, C>(self, callable: C) -> Concern<T, M> where
C: FnOnce(S) -> T,
Maps a Concern<S, M>
to Concern<T, F>
by applying a function to a
contained Success
value, leaving any Mistake
value untouched.
Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.map(|x| x + 1), Concern::Success(43));
let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.map(|x| x + 1), Concern::Mistake("hello"));
sourcepub fn map_mistake<N, C>(self, callable: C) -> Concern<S, N> where
C: FnOnce(M) -> N,
pub fn map_mistake<N, C>(self, callable: C) -> Concern<S, N> where
C: FnOnce(M) -> N,
Maps a Concern<S, M>
to Concern<S, N>
by applying a function to a
contained Mistake
value, leaving any Success
value untouched.
Examples
let x: Concern<u32, i32> = Concern::Success(42);
assert_eq!(x.map_mistake(|x| x + 1), Concern::Success(42));
let x: Concern<u32, i32> = Concern::Mistake(46);
assert_eq!(x.map_mistake(|x| x + 1), Concern::Mistake(47));
sourceimpl<S, M: Debug> Concern<S, M>
impl<S, M: Debug> Concern<S, M>
sourcepub fn unwrap(self) -> S
pub fn unwrap(self) -> S
Returns the contained Success
value, consuming the self
value.
Panics
Panics if the value is a Mistake
with a panic message provided by
their value.
Examples
let x: Concern<u32, &str> = Concern::Success(42);
assert_eq!(x.unwrap(), 42);
let x: Concern<u32, &str> = Concern::Mistake("hello");
x.unwrap(); // panics with "hello"
sourceimpl<S: Debug, M> Concern<S, M>
impl<S: Debug, M> Concern<S, M>
sourcepub fn unwrap_mistake(self) -> M
pub fn unwrap_mistake(self) -> M
Returns the contained Mistake
value, consuming the self
value.
Panics
Panics if the value is a Success
with a panic message provided by
their value.
Examples
let x: Concern<u32, &str> = Concern::Mistake("hello");
assert_eq!(x.unwrap_mistake(), "hello");
let x: Concern<u32, &str> = Concern::Success(42);
x.unwrap_mistake(); // panics with "42"
sourceimpl<S: Deref, M> Concern<S, M>
impl<S: Deref, M> Concern<S, M>
sourcepub fn as_deref(&self) -> Concern<&S::Target, &M>
pub fn as_deref(&self) -> Concern<&S::Target, &M>
Converts from Concern<S, M>
(or &Concern<S, M>
) to Concern<&<S as Deref>::Target, M>
.
Coerces the Success
variant of the original Concern
via Deref
and returns the new Concern
.
Examples
let x: Concern<String, u32> = Concern::Success("hello".to_string());
let y: Concern<&str, &u32> = Concern::Success("hello");
assert_eq!(x.as_deref(), y);
sourceimpl<S: DerefMut, M> Concern<S, M>
impl<S: DerefMut, M> Concern<S, M>
sourcepub fn as_deref_mut(&mut self) -> Concern<&mut S::Target, &mut M>
pub fn as_deref_mut(&mut self) -> Concern<&mut S::Target, &mut M>
Converts from Concern<S, M>
(or &mut Concern<S, M>
) to
Concern<&mut <S as DerefMut>::Target, &mut M>
.
Coerces the Success
variant of the original Concern
via
DerefMut
and returns the new Concern
Examples
let mut s = "HELLO".to_string();
let mut x: Concern<String, u32> = Concern::Success("hello".to_string());
let y: Concern<&mut str, &mut u32> = Concern::Success(&mut s);
assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
Trait Implementations
sourceimpl<S: Ord, M: Ord> Ord for Concern<S, M>
impl<S: Ord, M: Ord> Ord for Concern<S, M>
sourceimpl<S: PartialOrd, M: PartialOrd> PartialOrd<Concern<S, M>> for Concern<S, M>
impl<S: PartialOrd, M: PartialOrd> PartialOrd<Concern<S, M>> for Concern<S, M>
sourcefn partial_cmp(&self, other: &Concern<S, M>) -> Option<Ordering>
fn partial_cmp(&self, other: &Concern<S, M>) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl<S: Copy, M: Copy> Copy for Concern<S, M>
impl<S: Eq, M: Eq> Eq for Concern<S, M>
impl<S, M> StructuralEq for Concern<S, M>
impl<S, M> StructuralPartialEq for Concern<S, M>
Auto Trait Implementations
impl<S, M> RefUnwindSafe for Concern<S, M> where
M: RefUnwindSafe,
S: RefUnwindSafe,
impl<S, M> Send for Concern<S, M> where
M: Send,
S: Send,
impl<S, M> Sync for Concern<S, M> where
M: Sync,
S: Sync,
impl<S, M> Unpin for Concern<S, M> where
M: Unpin,
S: Unpin,
impl<S, M> UnwindSafe for Concern<S, M> where
M: UnwindSafe,
S: UnwindSafe,
Blanket Implementations
sourceimpl<T, U> AttemptFrom<U> for T where
U: Into<T>,
impl<T, U> AttemptFrom<U> for T where
U: Into<T>,
type Mistake = Infallible
type Mistake = Infallible
The retryable error type
type Failure = Infallible
type Failure = Infallible
The failure error type
sourcefn attempt_from(
value: U
) -> Outcome<T, <T as AttemptFrom<U>>::Mistake, <T as AttemptFrom<U>>::Failure>
fn attempt_from(
value: U
) -> Outcome<T, <T as AttemptFrom<U>>::Mistake, <T as AttemptFrom<U>>::Failure>
Performs the conversion
sourceimpl<T, U> AttemptInto<U> for T where
U: AttemptFrom<T>,
impl<T, U> AttemptInto<U> for T where
U: AttemptFrom<T>,
type Mistake = <U as AttemptFrom<T>>::Mistake
type Mistake = <U as AttemptFrom<T>>::Mistake
The type returned in the event of a conversion error where the caller may retry the conversion. Read more
type Failure = <U as AttemptFrom<T>>::Failure
type Failure = <U as AttemptFrom<T>>::Failure
The type returned in the event of a conversion error where the caller may not retry the conversion. Read more
sourcefn attempt_into(
self
) -> Outcome<U, <T as AttemptInto<U>>::Mistake, <T as AttemptInto<U>>::Failure>
fn attempt_into(
self
) -> Outcome<U, <T as AttemptInto<U>>::Mistake, <T as AttemptInto<U>>::Failure>
Performs the conversion.
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more