Enum frame_support::dispatch::result::Result
1.0.0 · source · pub enum Result<T, E> {
Ok(T),
Err(E),
}
Expand description
Result
is a type that represents either success (Ok
) or failure (Err
).
See the module documentation for details.
Variants§
Implementations§
source§impl<T, E> Result<T, E>
impl<T, E> Result<T, E>
sourcepub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool
🔬This is a nightly-only experimental API. (is_some_and
)
pub fn is_ok_and(self, f: impl FnOnce(T) -> bool) -> bool
is_some_and
)Returns true
if the result is Ok
and the value inside of it matches a predicate.
Examples
#![feature(is_some_and)]
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.is_ok_and(|x| x > 1), true);
let x: Result<u32, &str> = Ok(0);
assert_eq!(x.is_ok_and(|x| x > 1), false);
let x: Result<u32, &str> = Err("hey");
assert_eq!(x.is_ok_and(|x| x > 1), false);
sourcepub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool
🔬This is a nightly-only experimental API. (is_some_and
)
pub fn is_err_and(self, f: impl FnOnce(E) -> bool) -> bool
is_some_and
)Returns true
if the result is Err
and the value inside of it matches a predicate.
Examples
#![feature(is_some_and)]
use std::io::{Error, ErrorKind};
let x: Result<u32, Error> = Err(Error::new(ErrorKind::NotFound, "!"));
assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), true);
let x: Result<u32, Error> = Err(Error::new(ErrorKind::PermissionDenied, "!"));
assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
let x: Result<u32, Error> = Ok(123);
assert_eq!(x.is_err_and(|x| x.kind() == ErrorKind::NotFound), false);
const: unstable · sourcepub fn err(self) -> Option<E>
pub fn err(self) -> Option<E>
Converts from Result<T, E>
to Option<E>
.
Converts self
into an Option<E>
, consuming self
,
and discarding the success value, if any.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.err(), None);
let x: Result<u32, &str> = Err("Nothing here");
assert_eq!(x.err(), Some("Nothing here"));
const: 1.48.0 · sourcepub const fn as_ref(&self) -> Result<&T, &E>
pub const fn as_ref(&self) -> Result<&T, &E>
Converts from &Result<T, E>
to Result<&T, &E>
.
Produces a new Result
, containing a reference
into the original, leaving the original in place.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.as_ref(), Ok(&2));
let x: Result<u32, &str> = Err("Error");
assert_eq!(x.as_ref(), Err(&"Error"));
const: unstable · sourcepub fn as_mut(&mut self) -> Result<&mut T, &mut E>
pub fn as_mut(&mut self) -> Result<&mut T, &mut E>
Converts from &mut Result<T, E>
to Result<&mut T, &mut E>
.
Examples
Basic usage:
fn mutate(r: &mut Result<i32, i32>) {
match r.as_mut() {
Ok(v) => *v = 42,
Err(e) => *e = 0,
}
}
let mut x: Result<i32, i32> = Ok(2);
mutate(&mut x);
assert_eq!(x.unwrap(), 42);
let mut x: Result<i32, i32> = Err(13);
mutate(&mut x);
assert_eq!(x.unwrap_err(), 0);
sourcepub fn map<U, F>(self, op: F) -> Result<U, E>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, op: F) -> Result<U, E>where
F: FnOnce(T) -> U,
Maps a Result<T, E>
to Result<U, E>
by applying a function to a
contained Ok
value, leaving an Err
value untouched.
This function can be used to compose the results of two functions.
Examples
Print the numbers on each line of a string multiplied by two.
let line = "1\n2\n3\n4\n";
for num in line.lines() {
match num.parse::<i32>().map(|i| i * 2) {
Ok(n) => println!("{n}"),
Err(..) => {}
}
}
1.41.0 · sourcepub fn map_or<U, F>(self, default: U, f: F) -> Uwhere
F: FnOnce(T) -> U,
pub fn map_or<U, F>(self, default: U, f: F) -> Uwhere
F: FnOnce(T) -> U,
Returns the provided default (if Err
), or
applies a function to the contained value (if Ok
),
Arguments passed to map_or
are eagerly evaluated; if you are passing
the result of a function call, it is recommended to use map_or_else
,
which is lazily evaluated.
Examples
let x: Result<_, &str> = Ok("foo");
assert_eq!(x.map_or(42, |v| v.len()), 3);
let x: Result<&str, _> = Err("bar");
assert_eq!(x.map_or(42, |v| v.len()), 42);
1.41.0 · sourcepub fn map_or_else<U, D, F>(self, default: D, f: F) -> Uwhere
D: FnOnce(E) -> U,
F: FnOnce(T) -> U,
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> Uwhere
D: FnOnce(E) -> U,
F: FnOnce(T) -> U,
Maps a Result<T, E>
to U
by applying fallback function default
to
a contained Err
value, or function f
to a contained Ok
value.
This function can be used to unpack a successful result while handling an error.
Examples
Basic usage:
let k = 21;
let x : Result<_, &str> = Ok("foo");
assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 3);
let x : Result<&str, _> = Err("bar");
assert_eq!(x.map_or_else(|e| k * 2, |v| v.len()), 42);
sourcepub fn map_err<F, O>(self, op: O) -> Result<T, F>where
O: FnOnce(E) -> F,
pub fn map_err<F, O>(self, op: O) -> Result<T, F>where
O: FnOnce(E) -> F,
Maps a Result<T, E>
to Result<T, F>
by applying a function to a
contained Err
value, leaving an Ok
value untouched.
This function can be used to pass through a successful result while handling an error.
Examples
Basic usage:
fn stringify(x: u32) -> String { format!("error code: {x}") }
let x: Result<u32, u32> = Ok(2);
assert_eq!(x.map_err(stringify), Ok(2));
let x: Result<u32, u32> = Err(13);
assert_eq!(x.map_err(stringify), Err("error code: 13".to_string()));
sourcepub fn inspect<F>(self, f: F) -> Result<T, E>where
F: FnOnce(&T),
🔬This is a nightly-only experimental API. (result_option_inspect
)
pub fn inspect<F>(self, f: F) -> Result<T, E>where
F: FnOnce(&T),
result_option_inspect
)sourcepub fn inspect_err<F>(self, f: F) -> Result<T, E>where
F: FnOnce(&E),
🔬This is a nightly-only experimental API. (result_option_inspect
)
pub fn inspect_err<F>(self, f: F) -> Result<T, E>where
F: FnOnce(&E),
result_option_inspect
)1.47.0 · sourcepub fn as_deref(&self) -> Result<&<T as Deref>::Target, &E>where
T: Deref,
pub fn as_deref(&self) -> Result<&<T as Deref>::Target, &E>where
T: Deref,
Converts from Result<T, E>
(or &Result<T, E>
) to Result<&<T as Deref>::Target, &E>
.
Coerces the Ok
variant of the original Result
via Deref
and returns the new Result
.
Examples
let x: Result<String, u32> = Ok("hello".to_string());
let y: Result<&str, &u32> = Ok("hello");
assert_eq!(x.as_deref(), y);
let x: Result<String, u32> = Err(42);
let y: Result<&str, &u32> = Err(&42);
assert_eq!(x.as_deref(), y);
1.47.0 · sourcepub fn as_deref_mut(&mut self) -> Result<&mut <T as Deref>::Target, &mut E>where
T: DerefMut,
pub fn as_deref_mut(&mut self) -> Result<&mut <T as Deref>::Target, &mut E>where
T: DerefMut,
Converts from Result<T, E>
(or &mut Result<T, E>
) to Result<&mut <T as DerefMut>::Target, &mut E>
.
Coerces the Ok
variant of the original Result
via DerefMut
and returns the new Result
.
Examples
let mut s = "HELLO".to_string();
let mut x: Result<String, u32> = Ok("hello".to_string());
let y: Result<&mut str, &mut u32> = Ok(&mut s);
assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
let mut i = 42;
let mut x: Result<String, u32> = Err(42);
let y: Result<&mut str, &mut u32> = Err(&mut i);
assert_eq!(x.as_deref_mut().map(|x| { x.make_ascii_uppercase(); x }), y);
sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Returns an iterator over the possibly contained value.
The iterator yields one value if the result is Result::Ok
, otherwise none.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(7);
assert_eq!(x.iter().next(), Some(&7));
let x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter().next(), None);
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Returns a mutable iterator over the possibly contained value.
The iterator yields one value if the result is Result::Ok
, otherwise none.
Examples
Basic usage:
let mut x: Result<u32, &str> = Ok(7);
match x.iter_mut().next() {
Some(v) => *v = 40,
None => {},
}
assert_eq!(x, Ok(40));
let mut x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter_mut().next(), None);
1.4.0 · sourcepub fn expect(self, msg: &str) -> Twhere
E: Debug,
pub fn expect(self, msg: &str) -> Twhere
E: Debug,
Returns the contained Ok
value, consuming the self
value.
Because this function may panic, its use is generally discouraged.
Instead, prefer to use pattern matching and handle the Err
case explicitly, or call unwrap_or
, unwrap_or_else
, or
unwrap_or_default
.
Panics
Panics if the value is an Err
, with a panic message including the
passed message, and the content of the Err
.
Examples
Basic usage:
let x: Result<u32, &str> = Err("emergency failure");
x.expect("Testing expect"); // panics with `Testing expect: emergency failure`
Recommended Message Style
We recommend that expect
messages are used to describe the reason you
expect the Result
should be Ok
.
let path = std::env::var("IMPORTANT_PATH")
.expect("env variable `IMPORTANT_PATH` should be set by `wrapper_script.sh`");
Hint: If you’re having trouble remembering how to phrase expect error messages remember to focus on the word “should” as in “env variable should be set by blah” or “the given binary should be available and executable by the current user”.
For more detail on expect message styles and the reasoning behind our recommendation please
refer to the section on “Common Message
Styles” in the
std::error
module docs.
sourcepub fn unwrap(self) -> Twhere
E: Debug,
pub fn unwrap(self) -> Twhere
E: Debug,
Returns the contained Ok
value, consuming the self
value.
Because this function may panic, its use is generally discouraged.
Instead, prefer to use pattern matching and handle the Err
case explicitly, or call unwrap_or
, unwrap_or_else
, or
unwrap_or_default
.
Panics
Panics if the value is an Err
, with a panic message provided by the
Err
’s value.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.unwrap(), 2);
let x: Result<u32, &str> = Err("emergency failure");
x.unwrap(); // panics with `emergency failure`
1.16.0 · sourcepub fn unwrap_or_default(self) -> Twhere
T: Default,
pub fn unwrap_or_default(self) -> Twhere
T: Default,
Returns the contained Ok
value or a default
Consumes the self
argument then, if Ok
, returns the contained
value, otherwise if Err
, returns the default value for that
type.
Examples
Converts a string to an integer, turning poorly-formed strings
into 0 (the default value for integers). parse
converts
a string to any other type that implements FromStr
, returning an
Err
on error.
let good_year_from_input = "1909";
let bad_year_from_input = "190blarg";
let good_year = good_year_from_input.parse().unwrap_or_default();
let bad_year = bad_year_from_input.parse().unwrap_or_default();
assert_eq!(1909, good_year);
assert_eq!(0, bad_year);
1.17.0 · sourcepub fn expect_err(self, msg: &str) -> Ewhere
T: Debug,
pub fn expect_err(self, msg: &str) -> Ewhere
T: Debug,
Returns the contained Err
value, consuming the self
value.
Panics
Panics if the value is an Ok
, with a panic message including the
passed message, and the content of the Ok
.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(10);
x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10`
sourcepub fn unwrap_err(self) -> Ewhere
T: Debug,
pub fn unwrap_err(self) -> Ewhere
T: Debug,
Returns the contained Err
value, consuming the self
value.
Panics
Panics if the value is an Ok
, with a custom panic message provided
by the Ok
’s value.
Examples
let x: Result<u32, &str> = Ok(2);
x.unwrap_err(); // panics with `2`
let x: Result<u32, &str> = Err("emergency failure");
assert_eq!(x.unwrap_err(), "emergency failure");
sourcepub fn into_ok(self) -> Twhere
E: Into<!>,
🔬This is a nightly-only experimental API. (unwrap_infallible
)
pub fn into_ok(self) -> Twhere
E: Into<!>,
unwrap_infallible
)Returns the contained Ok
value, but never panics.
Unlike unwrap
, this method is known to never panic on the
result types it is implemented for. Therefore, it can be used
instead of unwrap
as a maintainability safeguard that will fail
to compile if the error type of the Result
is later changed
to an error that can actually occur.
Examples
Basic usage:
fn only_good_news() -> Result<String, !> {
Ok("this is fine".into())
}
let s: String = only_good_news().into_ok();
println!("{s}");
sourcepub fn into_err(self) -> Ewhere
T: Into<!>,
🔬This is a nightly-only experimental API. (unwrap_infallible
)
pub fn into_err(self) -> Ewhere
T: Into<!>,
unwrap_infallible
)Returns the contained Err
value, but never panics.
Unlike unwrap_err
, this method is known to never panic on the
result types it is implemented for. Therefore, it can be used
instead of unwrap_err
as a maintainability safeguard that will fail
to compile if the ok type of the Result
is later changed
to a type that can actually occur.
Examples
Basic usage:
fn only_bad_news() -> Result<!, String> {
Err("Oops, it failed".into())
}
let error: String = only_bad_news().into_err();
println!("{error}");
const: unstable · sourcepub fn and<U>(self, res: Result<U, E>) -> Result<U, E>
pub fn and<U>(self, res: Result<U, E>) -> Result<U, E>
Returns res
if the result is Ok
, otherwise returns the Err
value of self
.
Arguments passed to and
are eagerly evaluated; if you are passing the
result of a function call, it is recommended to use and_then
, which is
lazily evaluated.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2);
let y: Result<&str, &str> = Err("late error");
assert_eq!(x.and(y), Err("late error"));
let x: Result<u32, &str> = Err("early error");
let y: Result<&str, &str> = Ok("foo");
assert_eq!(x.and(y), Err("early error"));
let x: Result<u32, &str> = Err("not a 2");
let y: Result<&str, &str> = Err("late error");
assert_eq!(x.and(y), Err("not a 2"));
let x: Result<u32, &str> = Ok(2);
let y: Result<&str, &str> = Ok("different result type");
assert_eq!(x.and(y), Ok("different result type"));
sourcepub fn and_then<U, F>(self, op: F) -> Result<U, E>where
F: FnOnce(T) -> Result<U, E>,
pub fn and_then<U, F>(self, op: F) -> Result<U, E>where
F: FnOnce(T) -> Result<U, E>,
Calls op
if the result is Ok
, otherwise returns the Err
value of self
.
This function can be used for control flow based on Result
values.
Examples
fn sq_then_to_string(x: u32) -> Result<String, &'static str> {
x.checked_mul(x).map(|sq| sq.to_string()).ok_or("overflowed")
}
assert_eq!(Ok(2).and_then(sq_then_to_string), Ok(4.to_string()));
assert_eq!(Ok(1_000_000).and_then(sq_then_to_string), Err("overflowed"));
assert_eq!(Err("not a number").and_then(sq_then_to_string), Err("not a number"));
Often used to chain fallible operations that may return Err
.
use std::{io::ErrorKind, path::Path};
// Note: on Windows "/" maps to "C:\"
let root_modified_time = Path::new("/").metadata().and_then(|md| md.modified());
assert!(root_modified_time.is_ok());
let should_fail = Path::new("/bad/path").metadata().and_then(|md| md.modified());
assert!(should_fail.is_err());
assert_eq!(should_fail.unwrap_err().kind(), ErrorKind::NotFound);
const: unstable · sourcepub fn or<F>(self, res: Result<T, F>) -> Result<T, F>
pub fn or<F>(self, res: Result<T, F>) -> Result<T, F>
Returns res
if the result is Err
, otherwise returns the Ok
value of self
.
Arguments passed to or
are eagerly evaluated; if you are passing the
result of a function call, it is recommended to use or_else
, which is
lazily evaluated.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2);
let y: Result<u32, &str> = Err("late error");
assert_eq!(x.or(y), Ok(2));
let x: Result<u32, &str> = Err("early error");
let y: Result<u32, &str> = Ok(2);
assert_eq!(x.or(y), Ok(2));
let x: Result<u32, &str> = Err("not a 2");
let y: Result<u32, &str> = Err("late error");
assert_eq!(x.or(y), Err("late error"));
let x: Result<u32, &str> = Ok(2);
let y: Result<u32, &str> = Ok(100);
assert_eq!(x.or(y), Ok(2));
sourcepub fn or_else<F, O>(self, op: O) -> Result<T, F>where
O: FnOnce(E) -> Result<T, F>,
pub fn or_else<F, O>(self, op: O) -> Result<T, F>where
O: FnOnce(E) -> Result<T, F>,
Calls op
if the result is Err
, otherwise returns the Ok
value of self
.
This function can be used for control flow based on result values.
Examples
Basic usage:
fn sq(x: u32) -> Result<u32, u32> { Ok(x * x) }
fn err(x: u32) -> Result<u32, u32> { Err(x) }
assert_eq!(Ok(2).or_else(sq).or_else(sq), Ok(2));
assert_eq!(Ok(2).or_else(err).or_else(sq), Ok(2));
assert_eq!(Err(3).or_else(sq).or_else(err), Ok(9));
assert_eq!(Err(3).or_else(err).or_else(err), Err(3));
const: unstable · sourcepub fn unwrap_or(self, default: T) -> T
pub fn unwrap_or(self, default: T) -> T
Returns the contained Ok
value or a provided default.
Arguments passed to unwrap_or
are eagerly evaluated; if you are passing
the result of a function call, it is recommended to use unwrap_or_else
,
which is lazily evaluated.
Examples
Basic usage:
let default = 2;
let x: Result<u32, &str> = Ok(9);
assert_eq!(x.unwrap_or(default), 9);
let x: Result<u32, &str> = Err("error");
assert_eq!(x.unwrap_or(default), default);
sourcepub fn unwrap_or_else<F>(self, op: F) -> Twhere
F: FnOnce(E) -> T,
pub fn unwrap_or_else<F>(self, op: F) -> Twhere
F: FnOnce(E) -> T,
1.58.0 · sourcepub unsafe fn unwrap_unchecked(self) -> T
pub unsafe fn unwrap_unchecked(self) -> T
Returns the contained Ok
value, consuming the self
value,
without checking that the value is not an Err
.
Safety
Calling this method on an Err
is undefined behavior.
Examples
let x: Result<u32, &str> = Ok(2);
assert_eq!(unsafe { x.unwrap_unchecked() }, 2);
let x: Result<u32, &str> = Err("emergency failure");
unsafe { x.unwrap_unchecked(); } // Undefined behavior!
1.58.0 · sourcepub unsafe fn unwrap_err_unchecked(self) -> E
pub unsafe fn unwrap_err_unchecked(self) -> E
Returns the contained Err
value, consuming the self
value,
without checking that the value is not an Ok
.
Safety
Calling this method on an Ok
is undefined behavior.
Examples
let x: Result<u32, &str> = Ok(2);
unsafe { x.unwrap_err_unchecked() }; // Undefined behavior!
let x: Result<u32, &str> = Err("emergency failure");
assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure");
sourcepub fn contains<U>(&self, x: &U) -> boolwhere
U: PartialEq<T>,
🔬This is a nightly-only experimental API. (option_result_contains
)
pub fn contains<U>(&self, x: &U) -> boolwhere
U: PartialEq<T>,
option_result_contains
)Returns true
if the result is an Ok
value containing the given value.
Examples
#![feature(option_result_contains)]
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.contains(&2), true);
let x: Result<u32, &str> = Ok(3);
assert_eq!(x.contains(&2), false);
let x: Result<u32, &str> = Err("Some error message");
assert_eq!(x.contains(&2), false);
sourcepub fn contains_err<F>(&self, f: &F) -> boolwhere
F: PartialEq<E>,
🔬This is a nightly-only experimental API. (result_contains_err
)
pub fn contains_err<F>(&self, f: &F) -> boolwhere
F: PartialEq<E>,
result_contains_err
)Returns true
if the result is an Err
value containing the given value.
Examples
#![feature(result_contains_err)]
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.contains_err(&"Some error message"), false);
let x: Result<u32, &str> = Err("Some error message");
assert_eq!(x.contains_err(&"Some error message"), true);
let x: Result<u32, &str> = Err("Some other error message");
assert_eq!(x.contains_err(&"Some error message"), false);
source§impl<T, E> Result<&T, E>
impl<T, E> Result<&T, E>
source§impl<T, E> Result<&mut T, E>
impl<T, E> Result<&mut T, E>
1.59.0 · sourcepub fn copied(self) -> Result<T, E>where
T: Copy,
pub fn copied(self) -> Result<T, E>where
T: Copy,
Maps a Result<&mut T, E>
to a Result<T, E>
by copying the contents of the
Ok
part.
Examples
let mut val = 12;
let x: Result<&mut i32, i32> = Ok(&mut val);
assert_eq!(x, Ok(&mut 12));
let copied = x.copied();
assert_eq!(copied, Ok(12));
1.59.0 · sourcepub fn cloned(self) -> Result<T, E>where
T: Clone,
pub fn cloned(self) -> Result<T, E>where
T: Clone,
Maps a Result<&mut T, E>
to a Result<T, E>
by cloning the contents of the
Ok
part.
Examples
let mut val = 12;
let x: Result<&mut i32, i32> = Ok(&mut val);
assert_eq!(x, Ok(&mut 12));
let cloned = x.cloned();
assert_eq!(cloned, Ok(12));
source§impl<T, E> Result<Option<T>, E>
impl<T, E> Result<Option<T>, E>
1.33.0 (const: unstable) · sourcepub fn transpose(self) -> Option<Result<T, E>>
pub fn transpose(self) -> Option<Result<T, E>>
Transposes a Result
of an Option
into an Option
of a Result
.
Ok(None)
will be mapped to None
.
Ok(Some(_))
and Err(_)
will be mapped to Some(Ok(_))
and Some(Err(_))
.
Examples
#[derive(Debug, Eq, PartialEq)]
struct SomeErr;
let x: Result<Option<i32>, SomeErr> = Ok(Some(5));
let y: Option<Result<i32, SomeErr>> = Some(Ok(5));
assert_eq!(x.transpose(), y);
source§impl<T, E> Result<Result<T, E>, E>
impl<T, E> Result<Result<T, E>, E>
sourcepub fn flatten(self) -> Result<T, E>
🔬This is a nightly-only experimental API. (result_flattening
)
pub fn flatten(self) -> Result<T, E>
result_flattening
)Converts from Result<Result<T, E>, E>
to Result<T, E>
Examples
Basic usage:
#![feature(result_flattening)]
let x: Result<Result<&'static str, u32>, u32> = Ok(Ok("hello"));
assert_eq!(Ok("hello"), x.flatten());
let x: Result<Result<&'static str, u32>, u32> = Ok(Err(6));
assert_eq!(Err(6), x.flatten());
let x: Result<Result<&'static str, u32>, u32> = Err(6);
assert_eq!(Err(6), x.flatten());
Flattening only removes one level of nesting at a time:
#![feature(result_flattening)]
let x: Result<Result<Result<&'static str, u32>, u32>, u32> = Ok(Ok(Ok("hello")));
assert_eq!(Ok(Ok("hello")), x.flatten());
assert_eq!(Ok("hello"), x.flatten().flatten());
Trait Implementations§
source§impl<T, E> Context<T, E> for Result<T, E>where
E: 'static + StdError + Send + Sync,
impl<T, E> Context<T, E> for Result<T, E>where
E: 'static + StdError + Send + Sync,
source§impl<T, E> Decode for Result<T, E>where
T: Decode,
E: Decode,
impl<T, E> Decode for Result<T, E>where
T: Decode,
E: Decode,
source§impl<T, E: Debug> Defensive<T> for Result<T, E>
impl<T, E: Debug> Defensive<T> for Result<T, E>
source§fn defensive_unwrap_or(self, or: T) -> T
fn defensive_unwrap_or(self, or: T) -> T
unwrap_or
, but it does the defensive warnings explained in the trait
docs. Read moresource§fn defensive_unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
fn defensive_unwrap_or_else<F: FnOnce() -> T>(self, f: F) -> T
unwrap_or_else
, but it does the defensive warnings explained in the
trait docs. Read moresource§fn defensive_unwrap_or_default(self) -> Twhere
T: Default,
fn defensive_unwrap_or_default(self) -> Twhere
T: Default,
unwrap_or_default
, but it does the defensive warnings explained in the
trait docs. Read moresource§fn defensive(self) -> Self
fn defensive(self) -> Self
None
or Err
. Read moresource§fn defensive_proof(self, proof: &'static str) -> Self
fn defensive_proof(self, proof: &'static str) -> Self
Defensive::defensive
, but it takes a proof as input, and displays it if the
defensive operation has been triggered. Read moresource§impl<T, E: Debug> DefensiveResult<T, E> for Result<T, E>
impl<T, E: Debug> DefensiveResult<T, E> for Result<T, E>
source§fn defensive_map_err<F, O: FnOnce(E) -> F>(self, o: O) -> Result<T, F>
fn defensive_map_err<F, O: FnOnce(E) -> F>(self, o: O) -> Result<T, F>
source§fn defensive_map_or_else<U, D: FnOnce(E) -> U, F: FnOnce(T) -> U>(
self,
default: D,
f: F
) -> U
fn defensive_map_or_else<U, D: FnOnce(E) -> U, F: FnOnce(T) -> U>(
self,
default: D,
f: F
) -> U
U
), or call the default callback
if Err
, which should never happen. Read moresource§fn defensive_ok(self) -> Option<T>
fn defensive_ok(self) -> Option<T>
Err
variant if it
happens, which should never happen. Read moresource§impl<'de, T, E> Deserialize<'de> for Result<T, E>where
T: Deserialize<'de>,
E: Deserialize<'de>,
impl<'de, T, E> Deserialize<'de> for Result<T, E>where
T: Deserialize<'de>,
E: Deserialize<'de>,
source§fn deserialize<D>(
deserializer: D
) -> Result<Result<T, E>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Result<T, E>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
source§impl<T, E> Encode for Result<T, E>where
T: Encode,
E: Encode,
impl<T, E> Encode for Result<T, E>where
T: Encode,
E: Encode,
source§fn size_hint(&self) -> usize
fn size_hint(&self) -> usize
source§fn encode_to<W>(&self, dest: &mut W)where
W: Output + ?Sized,
fn encode_to<W>(&self, dest: &mut W)where
W: Output + ?Sized,
source§fn using_encoded<R, F>(&self, f: F) -> Rwhere
F: FnOnce(&[u8]) -> R,
fn using_encoded<R, F>(&self, f: F) -> Rwhere
F: FnOnce(&[u8]) -> R,
source§fn encoded_size(&self) -> usize
fn encoded_size(&self) -> usize
source§impl From<DispatchError> for Result<(), DispatchError>
impl From<DispatchError> for Result<(), DispatchError>
source§fn from(err: DispatchError) -> Result<(), DispatchError>
fn from(err: DispatchError) -> Result<(), DispatchError>
source§impl From<InvalidTransaction> for Result<ValidTransaction, TransactionValidityError>
impl From<InvalidTransaction> for Result<ValidTransaction, TransactionValidityError>
source§fn from(
invalid_transaction: InvalidTransaction
) -> Result<ValidTransaction, TransactionValidityError>
fn from(
invalid_transaction: InvalidTransaction
) -> Result<ValidTransaction, TransactionValidityError>
source§impl From<UnknownTransaction> for Result<ValidTransaction, TransactionValidityError>
impl From<UnknownTransaction> for Result<ValidTransaction, TransactionValidityError>
source§fn from(
unknown_transaction: UnknownTransaction
) -> Result<ValidTransaction, TransactionValidityError>
fn from(
unknown_transaction: UnknownTransaction
) -> Result<ValidTransaction, TransactionValidityError>
source§impl From<ValidTransactionBuilder> for Result<ValidTransaction, TransactionValidityError>
impl From<ValidTransactionBuilder> for Result<ValidTransaction, TransactionValidityError>
source§fn from(
builder: ValidTransactionBuilder
) -> Result<ValidTransaction, TransactionValidityError>
fn from(
builder: ValidTransactionBuilder
) -> Result<ValidTransaction, TransactionValidityError>
source§impl<A, E, V> FromIterator<Result<A, E>> for Result<V, E>where
V: FromIterator<A>,
impl<A, E, V> FromIterator<Result<A, E>> for Result<V, E>where
V: FromIterator<A>,
source§fn from_iter<I>(iter: I) -> Result<V, E>where
I: IntoIterator<Item = Result<A, E>>,
fn from_iter<I>(iter: I) -> Result<V, E>where
I: IntoIterator<Item = Result<A, E>>,
Takes each element in the Iterator
: if it is an Err
, no further
elements are taken, and the Err
is returned. Should no Err
occur, a
container with the values of each Result
is returned.
Here is an example which increments every integer in a vector, checking for overflow:
let v = vec![1, 2];
let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
x.checked_add(1).ok_or("Overflow!")
).collect();
assert_eq!(res, Ok(vec![2, 3]));
Here is another example that tries to subtract one from another list of integers, this time checking for underflow:
let v = vec![1, 2, 0];
let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32|
x.checked_sub(1).ok_or("Underflow!")
).collect();
assert_eq!(res, Err("Underflow!"));
Here is a variation on the previous example, showing that no
further elements are taken from iter
after the first Err
.
let v = vec![3, 2, 1, 10];
let mut shared = 0;
let res: Result<Vec<u32>, &'static str> = v.iter().map(|x: &u32| {
shared += x;
x.checked_sub(2).ok_or("Underflow!")
}).collect();
assert_eq!(res, Err("Underflow!"));
assert_eq!(shared, 6);
Since the third element caused an underflow, no further elements were taken,
so the final value of shared
is 6 (= 3 + 2 + 1
), not 16.
source§impl<C, T, E> FromParallelIterator<Result<T, E>> for Result<C, E>where
C: FromParallelIterator<T>,
T: Send,
E: Send,
impl<C, T, E> FromParallelIterator<Result<T, E>> for Result<C, E>where
C: FromParallelIterator<T>,
T: Send,
E: Send,
Collect an arbitrary Result
-wrapped collection.
If any item is Err
, then all previous Ok
items collected are
discarded, and it returns that error. If there are multiple errors, the
one returned is not deterministic.
source§fn from_par_iter<I>(par_iter: I) -> Result<C, E>where
I: IntoParallelIterator<Item = Result<T, E>>,
fn from_par_iter<I>(par_iter: I) -> Result<C, E>where
I: IntoParallelIterator<Item = Result<T, E>>,
par_iter
. Read moreconst: unstable · source§impl<T, E, F> FromResidual<Result<Infallible, E>> for Result<T, F>where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Result<T, F>where
F: From<E>,
const: unstable · source§fn from_residual(residual: Result<Infallible, E>) -> Result<T, F>
fn from_residual(residual: Result<Infallible, E>) -> Result<T, F>
try_trait_v2
)Residual
type. Read more1.4.0 · source§impl<'a, T, E> IntoIterator for &'a Result<T, E>
impl<'a, T, E> IntoIterator for &'a Result<T, E>
1.4.0 · source§impl<'a, T, E> IntoIterator for &'a mut Result<T, E>
impl<'a, T, E> IntoIterator for &'a mut Result<T, E>
source§impl<T, E> IntoIterator for Result<T, E>
impl<T, E> IntoIterator for Result<T, E>
source§fn into_iter(self) -> IntoIter<T> ⓘ
fn into_iter(self) -> IntoIter<T> ⓘ
Returns a consuming iterator over the possibly contained value.
The iterator yields one value if the result is Result::Ok
, otherwise none.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(5);
let v: Vec<u32> = x.into_iter().collect();
assert_eq!(v, [5]);
let x: Result<u32, &str> = Err("nothing!");
let v: Vec<u32> = x.into_iter().collect();
assert_eq!(v, []);
source§impl<'a, T, E> IntoParallelIterator for &'a Result<T, E>where
T: Sync,
impl<'a, T, E> IntoParallelIterator for &'a Result<T, E>where
T: Sync,
source§impl<'a, T, E> IntoParallelIterator for &'a mut Result<T, E>where
T: Send,
impl<'a, T, E> IntoParallelIterator for &'a mut Result<T, E>where
T: Send,
source§impl<T, E> IntoParallelIterator for Result<T, E>where
T: Send,
impl<T, E> IntoParallelIterator for Result<T, E>where
T: Send,
source§impl<T, E> MallocSizeOf for Result<T, E>where
T: MallocSizeOf,
E: MallocSizeOf,
impl<T, E> MallocSizeOf for Result<T, E>where
T: MallocSizeOf,
E: MallocSizeOf,
source§impl<T, E> MaxEncodedLen for Result<T, E>where
T: MaxEncodedLen,
E: MaxEncodedLen,
impl<T, E> MaxEncodedLen for Result<T, E>where
T: MaxEncodedLen,
E: MaxEncodedLen,
source§fn max_encoded_len() -> usize
fn max_encoded_len() -> usize
source§impl<T, E> Ord for Result<T, E>where
T: Ord,
E: Ord,
impl<T, E> Ord for Result<T, E>where
T: Ord,
E: Ord,
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl<T: PalletError, E: PalletError> PalletError for Result<T, E>
impl<T: PalletError, E: PalletError> PalletError for Result<T, E>
source§const MAX_ENCODED_SIZE: usize = _
const MAX_ENCODED_SIZE: usize = _
source§impl<T, E> PartialEq<Result<T, E>> for Result<T, E>where
T: PartialEq<T>,
E: PartialEq<E>,
impl<T, E> PartialEq<Result<T, E>> for Result<T, E>where
T: PartialEq<T>,
E: PartialEq<E>,
source§impl<T, E> PartialOrd<Result<T, E>> for Result<T, E>where
T: PartialOrd<T>,
E: PartialOrd<E>,
impl<T, E> PartialOrd<Result<T, E>> for Result<T, E>where
T: PartialOrd<T>,
E: PartialOrd<E>,
source§impl<T, E> Serialize for Result<T, E>where
T: Serialize,
E: Serialize,
impl<T, E> Serialize for Result<T, E>where
T: Serialize,
E: Serialize,
source§fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
1.16.0 · source§impl<T, U, E> Sum<Result<U, E>> for Result<T, E>where
T: Sum<U>,
impl<T, U, E> Sum<Result<U, E>> for Result<T, E>where
T: Sum<U>,
source§fn sum<I>(iter: I) -> Result<T, E>where
I: Iterator<Item = Result<U, E>>,
fn sum<I>(iter: I) -> Result<T, E>where
I: Iterator<Item = Result<U, E>>,
Takes each element in the Iterator
: if it is an Err
, no further
elements are taken, and the Err
is returned. Should no Err
occur, the sum of all elements is returned.
Examples
This sums up every integer in a vector, rejecting the sum if a negative element is encountered:
let v = vec![1, 2];
let res: Result<i32, &'static str> = v.iter().map(|&x: &i32|
if x < 0 { Err("Negative element found") }
else { Ok(x) }
).sum();
assert_eq!(res, Ok(3));
source§impl<T, E> TapFallible for Result<T, E>
impl<T, E> TapFallible for Result<T, E>
source§fn tap_ok(self, func: impl FnOnce(&T)) -> Result<T, E>
fn tap_ok(self, func: impl FnOnce(&T)) -> Result<T, E>
source§fn tap_ok_mut(self, func: impl FnOnce(&mut T)) -> Result<T, E>
fn tap_ok_mut(self, func: impl FnOnce(&mut T)) -> Result<T, E>
source§fn tap_err(self, func: impl FnOnce(&E)) -> Result<T, E>
fn tap_err(self, func: impl FnOnce(&E)) -> Result<T, E>
source§fn tap_err_mut(self, func: impl FnOnce(&mut E)) -> Result<T, E>
fn tap_err_mut(self, func: impl FnOnce(&mut E)) -> Result<T, E>
source§fn tap_ok_dbg(self, func: impl FnOnce(&Self::Ok)) -> Self
fn tap_ok_dbg(self, func: impl FnOnce(&Self::Ok)) -> Self
.tap_ok()
only in debug builds, and is erased in release builds.source§fn tap_ok_mut_dbg(self, func: impl FnOnce(&mut Self::Ok)) -> Self
fn tap_ok_mut_dbg(self, func: impl FnOnce(&mut Self::Ok)) -> Self
.tap_ok_mut()
only in debug builds, and is erased in release
builds. Read more1.61.0 · source§impl<T, E> Termination for Result<T, E>where
T: Termination,
E: Debug,
impl<T, E> Termination for Result<T, E>where
T: Termination,
E: Debug,
const: unstable · source§impl<T, E> Try for Result<T, E>
impl<T, E> Try for Result<T, E>
§type Output = T
type Output = T
try_trait_v2
)?
when not short-circuiting.§type Residual = Result<Infallible, E>
type Residual = Result<Infallible, E>
try_trait_v2
)FromResidual::from_residual
as part of ?
when short-circuiting. Read moreconst: unstable · source§fn from_output(output: <Result<T, E> as Try>::Output) -> Result<T, E>
fn from_output(output: <Result<T, E> as Try>::Output) -> Result<T, E>
try_trait_v2
)Output
type. Read moreconst: unstable · source§fn branch(
self
) -> ControlFlow<<Result<T, E> as Try>::Residual, <Result<T, E> as Try>::Output>
fn branch(
self
) -> ControlFlow<<Result<T, E> as Try>::Residual, <Result<T, E> as Try>::Output>
try_trait_v2
)?
to decide whether the operator should produce a value
(because this returned ControlFlow::Continue
)
or propagate a value back to the caller
(because this returned ControlFlow::Break
). Read moreimpl<T, E> Copy for Result<T, E>where
T: Copy,
E: Copy,
impl<T, LikeT, E, LikeE> EncodeLike<Result<LikeT, LikeE>> for Result<T, E>where
T: EncodeLike<LikeT>,
LikeT: Encode,
E: EncodeLike<LikeE>,
LikeE: Encode,
impl<T, E> Eq for Result<T, E>where
T: Eq,
E: Eq,
impl<T, E> StructuralEq for Result<T, E>
impl<T, E> StructuralPartialEq for Result<T, E>
impl<T> WasmRet for Result<T, Trap>where
T: WasmRet,
Auto Trait Implementations§
impl<T, E> RefUnwindSafe for Result<T, E>where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> Send for Result<T, E>where
E: Send,
T: Send,
impl<T, E> Sync for Result<T, E>where
E: Sync,
T: Sync,
impl<T, E> Unpin for Result<T, E>where
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for Result<T, E>where
E: UnwindSafe,
T: UnwindSafe,
Blanket Implementations§
source§impl<T> CallHasher for Twhere
T: Hash + ?Sized,
impl<T> CallHasher for Twhere
T: Hash + ?Sized,
source§impl<T> CheckedConversion for T
impl<T> CheckedConversion for T
source§impl<T> DecodeLimit for Twhere
T: Decode,
impl<T> DecodeLimit for Twhere
T: Decode,
source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
source§fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
fn into_any(self: Box<T, Global>) -> Box<dyn Any + 'static, Global>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
. Read moresource§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any + 'static>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
. Read moresource§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s. Read moresource§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s. Read moresource§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
source§impl<T> FromFFIValue for Twhere
T: PassBy,
impl<T> FromFFIValue for Twhere
T: PassBy,
§type SelfInstance = T
type SelfInstance = T
Self
can be an unsized type, it needs to be represented by a sized type at the host.
This SelfInstance
is the sized type. Read moresource§fn from_ffi_value(
context: &mut dyn FunctionContext,
arg: <<T as PassBy>::PassBy as RIType>::FFIType
) -> Result<T, String>
fn from_ffi_value(
context: &mut dyn FunctionContext,
arg: <<T as PassBy>::PassBy as RIType>::FFIType
) -> Result<T, String>
SelfInstance
from the givensource§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoFFIValue for Twhere
T: PassBy,
impl<T> IntoFFIValue for Twhere
T: PassBy,
source§fn into_ffi_value(
self,
context: &mut dyn FunctionContext
) -> Result<<<T as PassBy>::PassBy as RIType>::FFIType, String>
fn into_ffi_value(
self,
context: &mut dyn FunctionContext
) -> Result<<<T as PassBy>::PassBy as RIType>::FFIType, String>
self
into a ffi value.source§impl<'data, I> IntoParallelRefIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
impl<'data, I> IntoParallelRefIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
source§impl<'data, I> IntoParallelRefMutIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
impl<'data, I> IntoParallelRefMutIterator<'data> for Iwhere
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
§type Iter = <&'data mut I as IntoParallelIterator>::Iter
type Iter = <&'data mut I as IntoParallelIterator>::Iter
§type Item = <&'data mut I as IntoParallelIterator>::Item
type Item = <&'data mut I as IntoParallelIterator>::Item
&'data mut T
reference. Read moresource§fn par_iter_mut(
&'data mut self
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
fn par_iter_mut(
&'data mut self
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
self
. Read moresource§impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
impl<T, Outer> IsWrappedBy<Outer> for Twhere
Outer: AsRef<T> + AsMut<T> + From<T>,
T: From<Outer>,
source§impl<T> MallocSizeOfExt for Twhere
T: MallocSizeOf,
impl<T> MallocSizeOfExt for Twhere
T: MallocSizeOf,
source§fn malloc_size_of(&self) -> usize
fn malloc_size_of(&self) -> usize
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> Rwhere
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> Rwhere
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> Rwhere
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
self
, then passes self.as_ref()
into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> Rwhere
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatedConversion for T
impl<T> SaturatedConversion for T
source§fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
fn saturated_from<T>(t: T) -> Selfwhere
Self: UniqueSaturatedFrom<T>,
source§fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
fn saturated_into<T>(self) -> Twhere
Self: UniqueSaturatedInto<T>,
T
. Read moresource§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
Borrow<B>
of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
BorrowMut<B>
of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
AsRef<R>
view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
AsMut<R>
view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Selfwhere
Self: Deref<Target = T>,
T: ?Sized,
Deref::Target
of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Selfwhere
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Deref::Target
of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds. Read moresource§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Selfwhere
Self: Borrow<B>,
B: ?Sized,
.tap_borrow()
only in debug builds, and is erased in release
builds. Read moresource§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Selfwhere
Self: BorrowMut<B>,
B: ?Sized,
.tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read moresource§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Selfwhere
Self: AsRef<R>,
R: ?Sized,
.tap_ref()
only in debug builds, and is erased in release
builds. Read moresource§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Selfwhere
Self: AsMut<R>,
R: ?Sized,
.tap_ref_mut()
only in debug builds, and is erased in release
builds. Read moresource§impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
impl<S, T> UncheckedInto<T> for Swhere
T: UncheckedFrom<S>,
source§fn unchecked_into(self) -> T
fn unchecked_into(self) -> T
unchecked_from
.source§impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
impl<T, S> UniqueSaturatedInto<T> for Swhere
T: Bounded,
S: TryInto<T>,
source§fn unique_saturated_into(self) -> T
fn unique_saturated_into(self) -> T
T
.