Enum frame_support::dispatch::result::Result 1.0.0[−][src]
Result
is a type that represents either success (Ok
) or failure (Err
).
See the module documentation for details.
Variants
Contains the success value
Contains the error value
Implementations
impl<T, E> Result<T, E>
[src]
#[must_use =
"if you intended to assert that this is ok, consider `.unwrap()` instead"]pub const fn is_ok(&self) -> bool
1.0.0 (const: 1.48.0)[src]
Returns true
if the result is Ok
.
Examples
Basic usage:
let x: Result<i32, &str> = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result<i32, &str> = Err("Some error message"); assert_eq!(x.is_ok(), false);
#[must_use =
"if you intended to assert that this is err, consider `.unwrap_err()` instead"]pub const fn is_err(&self) -> bool
1.0.0 (const: 1.48.0)[src]
Returns true
if the result is Err
.
Examples
Basic usage:
let x: Result<i32, &str> = Ok(-3); assert_eq!(x.is_err(), false); let x: Result<i32, &str> = Err("Some error message"); assert_eq!(x.is_err(), true);
#[must_use]pub fn contains<U>(&self, x: &U) -> bool where
U: PartialEq<T>,
[src]
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);
#[must_use]pub fn contains_err<F>(&self, f: &F) -> bool where
F: PartialEq<E>,
[src]
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);
pub fn ok(self) -> Option<T>
[src]
Converts from Result<T, E>
to Option<T>
.
Converts self
into an Option<T>
, consuming self
,
and discarding the error, if any.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2); assert_eq!(x.ok(), Some(2)); let x: Result<u32, &str> = Err("Nothing here"); assert_eq!(x.ok(), None);
pub fn err(self) -> Option<E>
[src]
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"));
pub const fn as_ref(&self) -> Result<&T, &E>
1.0.0 (const: 1.48.0)[src]
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"));
pub fn as_mut(&mut self) -> Result<&mut T, &mut E>
[src]
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);
pub fn map<U, F>(self, op: F) -> Result<U, E> where
F: FnOnce(T) -> U,
[src]
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(..) => {} } }
pub fn map_or<U, F>(self, default: U, f: F) -> U where
F: FnOnce(T) -> U,
1.41.0[src]
F: FnOnce(T) -> U,
Applies a function to the contained value (if Ok
),
or returns the provided default (if Err
).
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);
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> U where
F: FnOnce(T) -> U,
D: FnOnce(E) -> U,
1.41.0[src]
F: FnOnce(T) -> U,
D: FnOnce(E) -> U,
Maps a Result<T, E>
to U
by applying a function to a
contained Ok
value, or a fallback function to a
contained Err
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);
pub fn map_err<F, O>(self, op: O) -> Result<T, F> where
O: FnOnce(E) -> F,
[src]
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()));
pub fn iter(&self) -> Iter<'_, T>ⓘ
[src]
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);
pub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘ
[src]
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);
pub fn and<U>(self, res: Result<U, E>) -> Result<U, E>
[src]
Returns res
if the result is Ok
, otherwise returns the Err
value of self
.
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"));
pub fn and_then<U, F>(self, op: F) -> Result<U, E> where
F: FnOnce(T) -> Result<U, E>,
[src]
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
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).and_then(sq).and_then(sq), Ok(16)); assert_eq!(Ok(2).and_then(sq).and_then(err), Err(4)); assert_eq!(Ok(2).and_then(err).and_then(sq), Err(2)); assert_eq!(Err(3).and_then(sq).and_then(sq), Err(3));
pub fn or<F>(self, res: Result<T, F>) -> Result<T, F>
[src]
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));
pub fn or_else<F, O>(self, op: O) -> Result<T, F> where
O: FnOnce(E) -> Result<T, F>,
[src]
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));
pub fn unwrap_or(self, default: T) -> T
[src]
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);
pub fn unwrap_or_else<F>(self, op: F) -> T where
F: FnOnce(E) -> T,
[src]
F: FnOnce(E) -> T,
Returns the contained Ok
value or computes it from a closure.
Examples
Basic usage:
fn count(x: &str) -> usize { x.len() } assert_eq!(Ok(2).unwrap_or_else(count), 2); assert_eq!(Err("foo").unwrap_or_else(count), 3);
pub unsafe fn unwrap_unchecked(self) -> T
[src]
🔬 This is a nightly-only experimental API. (option_result_unwrap_unchecked
)
newly added
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
#![feature(option_result_unwrap_unchecked)] let x: Result<u32, &str> = Ok(2); assert_eq!(unsafe { x.unwrap_unchecked() }, 2);
#![feature(option_result_unwrap_unchecked)] let x: Result<u32, &str> = Err("emergency failure"); unsafe { x.unwrap_unchecked(); } // Undefined behavior!
pub unsafe fn unwrap_err_unchecked(self) -> E
[src]
🔬 This is a nightly-only experimental API. (option_result_unwrap_unchecked
)
newly added
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
#![feature(option_result_unwrap_unchecked)] let x: Result<u32, &str> = Ok(2); unsafe { x.unwrap_err_unchecked() }; // Undefined behavior!
#![feature(option_result_unwrap_unchecked)] let x: Result<u32, &str> = Err("emergency failure"); assert_eq!(unsafe { x.unwrap_err_unchecked() }, "emergency failure");
impl<'_, T, E> Result<&'_ T, E> where
T: Copy,
[src]
T: Copy,
pub fn copied(self) -> Result<T, E>
[src]
🔬 This is a nightly-only experimental API. (result_copied
)
newly added
Maps a Result<&T, E>
to a Result<T, E>
by copying the contents of the
Ok
part.
Examples
#![feature(result_copied)] let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12));
impl<'_, T, E> Result<&'_ mut T, E> where
T: Copy,
[src]
T: Copy,
pub fn copied(self) -> Result<T, E>
[src]
🔬 This is a nightly-only experimental API. (result_copied
)
newly added
Maps a Result<&mut T, E>
to a Result<T, E>
by copying the contents of the
Ok
part.
Examples
#![feature(result_copied)] 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));
impl<'_, T, E> Result<&'_ T, E> where
T: Clone,
[src]
T: Clone,
pub fn cloned(self) -> Result<T, E>
[src]
🔬 This is a nightly-only experimental API. (result_cloned
)
newly added
Maps a Result<&T, E>
to a Result<T, E>
by cloning the contents of the
Ok
part.
Examples
#![feature(result_cloned)] let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12));
impl<'_, T, E> Result<&'_ mut T, E> where
T: Clone,
[src]
T: Clone,
pub fn cloned(self) -> Result<T, E>
[src]
🔬 This is a nightly-only experimental API. (result_cloned
)
newly added
Maps a Result<&mut T, E>
to a Result<T, E>
by cloning the contents of the
Ok
part.
Examples
#![feature(result_cloned)] 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));
impl<T, E> Result<T, E> where
E: Debug,
[src]
E: Debug,
pub fn expect(self, msg: &str) -> T
1.4.0[src]
Returns the contained Ok
value, consuming the self
value.
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`
pub fn unwrap(self) -> T
[src]
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`
impl<T, E> Result<T, E> where
T: Debug,
[src]
T: Debug,
pub fn expect_err(self, msg: &str) -> E
1.17.0[src]
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`
pub fn unwrap_err(self) -> E
[src]
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");
impl<T, E> Result<T, E> where
T: Default,
[src]
T: Default,
pub fn unwrap_or_default(self) -> T
1.16.0[src]
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);
impl<T, E> Result<T, E> where
E: Into<!>,
[src]
E: Into<!>,
pub fn into_ok(self) -> T
[src]
🔬 This is a nightly-only experimental API. (unwrap_infallible
)
newly added
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);
impl<T, E> Result<T, E> where
T: Deref,
[src]
T: Deref,
pub fn as_deref(&self) -> Result<&<T as Deref>::Target, &E>
1.47.0[src]
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);
impl<T, E> Result<T, E> where
T: DerefMut,
[src]
T: DerefMut,
pub fn as_deref_mut(&mut self) -> Result<&mut <T as Deref>::Target, &mut E>
1.47.0[src]
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);
impl<T, E> Result<Option<T>, E>
[src]
pub const fn transpose(self) -> Option<Result<T, E>>
1.33.0[src]
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);
impl<T, E> Result<Result<T, E>, E>
[src]
pub fn flatten(self) -> Result<T, E>
[src]
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());
impl<T> Result<T, T>
[src]
pub const fn into_ok_or_err(self) -> T
[src]
🔬 This is a nightly-only experimental API. (result_into_ok_or_err
)
newly added
Returns the Ok
value if self
is Ok
, and the Err
value if
self
is Err
.
In other words, this function returns the value (the T
) of a
Result<T, T>
, regardless of whether or not that result is Ok
or
Err
.
This can be useful in conjunction with APIs such as
Atomic*::compare_exchange
, or slice::binary_search
, but only in
cases where you don’t care if the result was Ok
or not.
Examples
#![feature(result_into_ok_or_err)] let ok: Result<u32, u32> = Ok(3); let err: Result<u32, u32> = Err(4); assert_eq!(ok.into_ok_or_err(), 3); assert_eq!(err.into_ok_or_err(), 4);
Trait Implementations
impl<T, E> Clone for Result<T, E> where
T: Clone,
E: Clone,
[src]
T: Clone,
E: Clone,
impl<T, E> Copy for Result<T, E> where
T: Copy,
E: Copy,
[src]
T: Copy,
E: Copy,
impl<T, E> Debug for Result<T, E> where
T: Debug,
E: Debug,
[src]
T: Debug,
E: Debug,
impl<T, E> Decode for Result<T, E> where
T: Decode,
E: Decode,
[src]
T: Decode,
E: Decode,
impl<'de, T, E> Deserialize<'de> for Result<T, E> where
T: Deserialize<'de>,
E: Deserialize<'de>,
[src]
T: Deserialize<'de>,
E: Deserialize<'de>,
pub fn deserialize<D>(
deserializer: D
) -> Result<Result<T, E>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
[src]
deserializer: D
) -> Result<Result<T, E>, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
impl<T, E> Encode for Result<T, E> where
T: Encode,
E: Encode,
[src]
T: Encode,
E: Encode,
pub fn size_hint(&self) -> usize
[src]
pub fn encode_to<W>(&self, dest: &mut W) where
W: Output,
[src]
W: Output,
pub fn encode(&self) -> Vec<u8, Global>ⓘ
[src]
pub fn using_encoded<R, F>(&self, f: F) -> R where
F: FnOnce(&[u8]) -> R,
[src]
F: FnOnce(&[u8]) -> R,
impl<T, LikeT, E, LikeE> EncodeLike<Result<LikeT, LikeE>> for Result<T, E> where
T: EncodeLike<LikeT>,
E: EncodeLike<LikeE>,
LikeT: Encode,
LikeE: Encode,
[src]
T: EncodeLike<LikeT>,
E: EncodeLike<LikeE>,
LikeT: Encode,
LikeE: Encode,
impl<T, E> Eq for Result<T, E> where
T: Eq,
E: Eq,
[src]
T: Eq,
E: Eq,
impl<'_> From<&'_ StreamResult> for Result<MZStatus, MZError>
[src]
impl<'_> From<&'_ StreamResult> for Result<MZStatus, MZError>
[src]
impl From<DispatchError> for Result<(), DispatchError>
[src]
pub fn from(err: DispatchError) -> Result<(), DispatchError>
[src]
impl From<StreamResult> for Result<MZStatus, MZError>
[src]
impl From<StreamResult> for Result<MZStatus, MZError>
[src]
impl From<ValidTransactionBuilder> for Result<ValidTransaction, TransactionValidityError>
[src]
pub fn from(
builder: ValidTransactionBuilder
) -> Result<ValidTransaction, TransactionValidityError>
[src]
builder: ValidTransactionBuilder
) -> Result<ValidTransaction, TransactionValidityError>
impl<A, E, V> FromIterator<Result<A, E>> for Result<V, E> where
V: FromIterator<A>,
[src]
V: FromIterator<A>,
pub fn from_iter<I>(iter: I) -> Result<V, E> where
I: IntoIterator<Item = Result<A, E>>,
[src]
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.
impl<C, T, E> FromParallelIterator<Result<T, E>> for Result<C, E> where
C: FromParallelIterator<T>,
T: Send,
E: Send,
[src]
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.
pub fn from_par_iter<I>(par_iter: I) -> Result<C, E> where
I: IntoParallelIterator<Item = Result<T, E>>,
[src]
I: IntoParallelIterator<Item = Result<T, E>>,
impl<T, E> Hash for Result<T, E> where
T: Hash,
E: Hash,
[src]
T: Hash,
E: Hash,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, E> IntoFuture for Result<T, E>
[src]
type Future = FutureResult<T, E>
The future that this type can be converted into.
type Item = T
The item that the future may resolve with.
type Error = E
The error that the future may resolve with.
pub fn into_future(self) -> FutureResult<T, E>
[src]
impl<'a, T, E> IntoIterator for &'a mut Result<T, E>
1.4.0[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> IterMut<'a, T>ⓘ
[src]
impl<T, E> IntoIterator for Result<T, E>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> IntoIter<T>ⓘ
[src]
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, []);
impl<'a, T, E> IntoIterator for &'a Result<T, E>
1.4.0[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
pub fn into_iter(self) -> Iter<'a, T>ⓘ
[src]
impl<'a, T, E> IntoParallelIterator for &'a mut Result<T, E> where
T: Send,
[src]
T: Send,
type Item = &'a mut T
The type of item that the parallel iterator will produce.
type Iter = IterMut<'a, T>
The parallel iterator type that will be created.
pub fn into_par_iter(
self
) -> <&'a mut Result<T, E> as IntoParallelIterator>::Iter
[src]
self
) -> <&'a mut Result<T, E> as IntoParallelIterator>::Iter
impl<'a, T, E> IntoParallelIterator for &'a Result<T, E> where
T: Sync,
[src]
T: Sync,
type Item = &'a T
The type of item that the parallel iterator will produce.
type Iter = Iter<'a, T>
The parallel iterator type that will be created.
pub fn into_par_iter(self) -> <&'a Result<T, E> as IntoParallelIterator>::Iter
[src]
impl<T, E> IntoParallelIterator for Result<T, E> where
T: Send,
[src]
T: Send,
type Item = T
The type of item that the parallel iterator will produce.
type Iter = IntoIter<T>
The parallel iterator type that will be created.
pub fn into_par_iter(self) -> <Result<T, E> as IntoParallelIterator>::Iter
[src]
impl<T, E> MallocSizeOf for Result<T, E> where
T: MallocSizeOf,
E: MallocSizeOf,
[src]
T: MallocSizeOf,
E: MallocSizeOf,
pub fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize
[src]
pub fn constant_size() -> Option<usize>
[src]
impl<T, E> Ord for Result<T, E> where
T: Ord,
E: Ord,
[src]
T: Ord,
E: Ord,
pub fn cmp(&self, other: &Result<T, E>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<T, E> PartialEq<Result<T, E>> for Result<T, E> where
T: PartialEq<T>,
E: PartialEq<E>,
[src]
T: PartialEq<T>,
E: PartialEq<E>,
pub fn eq(&self, other: &Result<T, E>) -> bool
[src]
pub fn ne(&self, other: &Result<T, E>) -> bool
[src]
impl<T, E> PartialOrd<Result<T, E>> for Result<T, E> where
T: PartialOrd<T>,
E: PartialOrd<E>,
[src]
T: PartialOrd<T>,
E: PartialOrd<E>,
pub fn partial_cmp(&self, other: &Result<T, E>) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
[src]
impl<T, E> PassBy for Result<T, E> where
T: Codec,
E: Codec,
[src]
T: Codec,
E: Codec,
impl<T, U, E> Product<Result<U, E>> for Result<T, E> where
T: Product<U>,
1.16.0[src]
T: Product<U>,
impl<T, E> ResultExt<T, E> for Result<T, E> where
E: Fail,
[src]
E: Fail,
pub fn compat(self) -> Result<T, Compat<E>>
[src]
pub fn context<D>(self, context: D) -> Result<T, Context<D>> where
D: Display + Send + Sync + 'static,
[src]
D: Display + Send + Sync + 'static,
pub fn with_context<F, D>(self, f: F) -> Result<T, Context<D>> where
F: FnOnce(&E) -> D,
D: Display + Send + Sync + 'static,
[src]
F: FnOnce(&E) -> D,
D: Display + Send + Sync + 'static,
impl<T> ResultExt<T, Error> for Result<T, Error>
[src]
pub fn compat(self) -> Result<T, Compat<Error>>
[src]
pub fn context<D>(self, context: D) -> Result<T, Context<D>> where
D: Display + Send + Sync + 'static,
[src]
D: Display + Send + Sync + 'static,
pub fn with_context<F, D>(self, f: F) -> Result<T, Context<D>> where
F: FnOnce(&Error) -> D,
D: Display + Send + Sync + 'static,
[src]
F: FnOnce(&Error) -> D,
D: Display + Send + Sync + 'static,
impl<T, E> Serialize for Result<T, E> where
T: Serialize,
E: Serialize,
[src]
T: Serialize,
E: Serialize,
pub fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
[src]
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
impl<T, E> StructuralEq for Result<T, E>
[src]
impl<T, E> StructuralPartialEq for Result<T, E>
[src]
impl<T, U, E> Sum<Result<U, E>> for Result<T, E> where
T: Sum<U>,
1.16.0[src]
T: Sum<U>,
pub fn sum<I>(iter: I) -> Result<T, E> where
I: Iterator<Item = Result<U, E>>,
[src]
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));
impl<E> Termination for Result<!, E> where
E: Debug,
[src]
E: Debug,
impl<E> Termination for Result<(), E> where
E: Debug,
[src]
E: Debug,
impl<T, E> Try for Result<T, E>
[src]
type Ok = T
try_trait
)The type of this value when viewed as successful.
type Error = E
try_trait
)The type of this value when viewed as failed.
pub fn into_result(self) -> Result<T, E>
[src]
pub fn from_ok(v: T) -> Result<T, E>
[src]
pub fn from_error(v: E) -> Result<T, E>
[src]
Auto Trait Implementations
impl<T, E> RefUnwindSafe for Result<T, E> where
E: RefUnwindSafe,
T: RefUnwindSafe,
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> Send for Result<T, E> where
E: Send,
T: Send,
E: Send,
T: Send,
impl<T, E> Sync for Result<T, E> where
E: Sync,
T: Sync,
E: Sync,
T: Sync,
impl<T, E> Unpin for Result<T, E> where
E: Unpin,
T: Unpin,
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for Result<T, E> where
E: UnwindSafe,
T: UnwindSafe,
E: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CallHasher for T where
T: Hash,
[src]
T: Hash,
impl<T> CheckedConversion for T
[src]
pub fn checked_from<T>(t: T) -> Option<Self> where
Self: TryFrom<T>,
[src]
Self: TryFrom<T>,
pub fn checked_into<T>(self) -> Option<T> where
Self: TryInto<T>,
[src]
Self: TryInto<T>,
impl<S> Codec for S where
S: Encode + Decode,
[src]
S: Encode + Decode,
impl<T> DecodeAll for T where
T: Decode,
[src]
T: Decode,
impl<T> DecodeLimit for T where
T: Decode,
[src]
T: Decode,
pub fn decode_all_with_depth_limit(limit: u32, input: &[u8]) -> Result<T, Error>
[src]
pub fn decode_with_depth_limit(limit: u32, input: &[u8]) -> Result<T, Error>
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> DynClone for T where
T: Clone,
[src]
T: Clone,
pub fn __clone_box(&self, Private) -> *mut ()
[src]
impl<'_, '_, T> EncodeLike<&'_ &'_ T> for T where
T: Encode,
[src]
T: Encode,
impl<'_, T> EncodeLike<&'_ T> for T where
T: Encode,
[src]
T: Encode,
impl<'_, T> EncodeLike<&'_ mut T> for T where
T: Encode,
[src]
T: Encode,
impl<T> EncodeLike<Arc<T>> for T where
T: Encode,
[src]
T: Encode,
impl<T> EncodeLike<Box<T, Global>> for T where
T: Encode,
[src]
T: Encode,
impl<'a, T> EncodeLike<Cow<'a, T>> for T where
T: Encode + ToOwned,
[src]
T: Encode + ToOwned,
impl<T> EncodeLike<Rc<T>> for T where
T: Encode,
[src]
T: Encode,
impl<T> From<T> for T
[src]
impl<T> FromFFIValue for T where
T: PassBy,
[src]
T: PassBy,
type SelfInstance = T
As 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 more
pub fn from_ffi_value(
context: &mut dyn FunctionContext,
arg: <<T as PassBy>::PassBy as RIType>::FFIType
) -> Result<T, String>
[src]
context: &mut dyn FunctionContext,
arg: <<T as PassBy>::PassBy as RIType>::FFIType
) -> Result<T, String>
impl<S> FullCodec for S where
S: Decode + FullEncode,
[src]
S: Decode + FullEncode,
impl<S> FullEncode for S where
S: Encode + EncodeLike<S>,
[src]
S: Encode + EncodeLike<S>,
impl<T> Instrument for T
[src]
pub fn instrument(self, span: Span) -> Instrumented<Self>
[src]
pub fn in_current_span(self) -> Instrumented<Self>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> IntoFFIValue for T where
T: PassBy,
[src]
T: PassBy,
pub fn into_ffi_value(
self,
context: &mut dyn FunctionContext
) -> Result<<<T as PassBy>::PassBy as RIType>::FFIType, String>
[src]
self,
context: &mut dyn FunctionContext
) -> Result<<<T as PassBy>::PassBy as RIType>::FFIType, String>
impl<'data, I> IntoParallelRefIterator<'data> for I where
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
[src]
I: 'data + ?Sized,
&'data I: IntoParallelIterator,
type Iter = <&'data I as IntoParallelIterator>::Iter
The type of the parallel iterator that will be returned.
type Item = <&'data I as IntoParallelIterator>::Item
The type of item that the parallel iterator will produce.
This will typically be an &'data T
reference type. Read more
pub fn par_iter(&'data self) -> <I as IntoParallelRefIterator<'data>>::Iter
[src]
impl<'data, I> IntoParallelRefMutIterator<'data> for I where
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
[src]
I: 'data + ?Sized,
&'data mut I: IntoParallelIterator,
type Iter = <&'data mut I as IntoParallelIterator>::Iter
The type of iterator that will be created.
type Item = <&'data mut I as IntoParallelIterator>::Item
The type of item that will be produced; this is typically an
&'data mut T
reference. Read more
pub fn par_iter_mut(
&'data mut self
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
[src]
&'data mut self
) -> <I as IntoParallelRefMutIterator<'data>>::Iter
impl<T> IsType<T> for T
[src]
pub fn from_ref(&T) -> &T
[src]
pub fn into_ref(&Self) -> &T
[src]
pub fn from_mut(&mut T) -> &mut T
[src]
pub fn into_mut(&mut Self) -> &mut T
[src]
impl<T, Outer> IsWrappedBy<Outer> for T where
T: From<Outer>,
Outer: AsRef<T> + AsMut<T> + From<T>,
[src]
T: From<Outer>,
Outer: AsRef<T> + AsMut<T> + From<T>,
pub fn from_ref(outer: &Outer) -> &T
[src]
Get a reference to the inner from the outer.
pub fn from_mut(outer: &mut Outer) -> &mut T
[src]
Get a mutable reference to the inner from the outer.
impl<T> KeyedVec for T where
T: Codec,
[src]
T: Codec,
impl<T> MallocSizeOfExt for T where
T: MallocSizeOf,
[src]
T: MallocSizeOf,
pub fn malloc_size_of(&self) -> usize
[src]
impl<T> MaybeDebug for T where
T: Debug,
[src]
T: Debug,
impl<T> MaybeDebug for T where
T: Debug,
[src]
T: Debug,
impl<T> MaybeHash for T where
T: Hash,
[src]
T: Hash,
impl<T> MaybeHash for T where
T: Hash,
[src]
T: Hash,
impl<T> MaybeMallocSizeOf for T where
T: MallocSizeOf,
[src]
T: MallocSizeOf,
impl<T> MaybeRefUnwindSafe for T where
T: RefUnwindSafe,
[src]
T: RefUnwindSafe,
impl<T> MaybeSerialize for T where
T: Serialize,
[src]
T: Serialize,
impl<T> MaybeSerializeDeserialize for T where
T: DeserializeOwned + Serialize,
[src]
T: DeserializeOwned + Serialize,
impl<T> Member for T where
T: 'static + Clone + PartialEq<T> + Eq + Send + Sync + Debug,
[src]
T: 'static + Clone + PartialEq<T> + Eq + Send + Sync + Debug,
impl<T> Parameter for T where
T: Codec + EncodeLike<T> + Clone + Eq + Debug,
[src]
T: Codec + EncodeLike<T> + Clone + Eq + Debug,
impl<T> Pointable for T
[src]
pub const ALIGN: usize
[src]
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
[src]
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
[src]
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
[src]
pub unsafe fn drop(ptr: usize)
[src]
impl<T> RIType for T where
T: PassBy,
[src]
T: PassBy,
type FFIType = <<T as PassBy>::PassBy as RIType>::FFIType
The ffi type that is used to represent Self
.
impl<T> Same<T> for T
[src]
type Output = T
Should always be Self
impl<T> SaturatedConversion for T
[src]
pub fn saturated_from<T>(t: T) -> Self where
Self: UniqueSaturatedFrom<T>,
[src]
Self: UniqueSaturatedFrom<T>,
pub fn saturated_into<T>(self) -> T where
Self: UniqueSaturatedInto<T>,
[src]
Self: UniqueSaturatedInto<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<S, T> UncheckedInto<T> for S where
T: UncheckedFrom<S>,
[src]
T: UncheckedFrom<S>,
pub fn unchecked_into(self) -> T
[src]
impl<T, S> UniqueSaturatedInto<T> for S where
T: Bounded,
S: TryInto<T>,
[src]
T: Bounded,
S: TryInto<T>,
pub fn unique_saturated_into(self) -> T
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
[src]
V: MultiLane<T>,