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>
1.70.0 (const: unstable) ยท Sourcepub fn is_ok_and<F>(self, f: F) -> bool
pub fn is_ok_and<F>(self, f: F) -> bool
Returns true
if the result is Ok
and the value inside of it matches a predicate.
ยงExamples
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);
let x: Result<String, &str> = Ok("ownership".to_string());
assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true);
println!("still alive {:?}", x);
1.70.0 (const: unstable) ยท Sourcepub fn is_err_and<F>(self, f: F) -> bool
pub fn is_err_and<F>(self, f: F) -> bool
Returns true
if the result is Err
and the value inside of it matches a predicate.
ยงExamples
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);
let x: Result<u32, String> = Err("ownership".to_string());
assert_eq!(x.as_ref().is_err_and(|x| x.len() > 1), true);
println!("still alive {:?}", x);
1.0.0 (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
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"));
1.0.0 (const: 1.83.0) ยท Sourcepub const fn as_mut(&mut self) -> Result<&mut T, &mut E>
pub const fn as_mut(&mut self) -> Result<&mut T, &mut E>
Converts from &mut Result<T, E>
to Result<&mut T, &mut E>
.
ยงExamples
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);
1.0.0 (const: unstable) ยท 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 (const: unstable) ยท 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 (const: unstable) ยท Sourcepub fn map_or_else<U, D, F>(self, default: D, f: F) -> U
pub fn map_or_else<U, D, F>(self, default: D, f: F) -> 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
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 const fn map_or_default<U, F>(self, f: F) -> U
๐ฌThis is a nightly-only experimental API. (result_option_map_or_default
)
pub const fn map_or_default<U, F>(self, f: F) -> U
result_option_map_or_default
)Maps a Result<T, E>
to a U
by applying function f
to the contained
value if the result is Ok
, otherwise if Err
, returns the
default value for the type U
.
ยงExamples
#![feature(result_option_map_or_default)]
let x: Result<_, &str> = Ok("foo");
let y: Result<&str, _> = Err("bar");
assert_eq!(x.map_or_default(|x| x.len()), 3);
assert_eq!(y.map_or_default(|y| y.len()), 0);
1.0.0 (const: unstable) ยท 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
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()));
1.76.0 (const: unstable) ยท Sourcepub fn inspect_err<F>(self, f: F) -> Result<T, E>
pub fn inspect_err<F>(self, f: F) -> Result<T, E>
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);
1.0.0 (const: unstable) ยท 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
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);
1.0.0 (const: unstable) ยท 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
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
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.
1.0.0 ยท 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. Panics are meant for unrecoverable errors, and may abort the entire program.
Instead, prefer to use the ?
(try) operator, or pattern matching
to 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 (const: unstable) ยท 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
let x: Result<u32, &str> = Ok(10);
x.expect_err("Testing expect_err"); // panics with `Testing expect_err: 10`
1.0.0 ยท 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 const fn into_ok(self) -> T
๐ฌThis is a nightly-only experimental API. (unwrap_infallible
)
pub const fn into_ok(self) -> T
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
fn only_good_news() -> Result<String, !> {
Ok("this is fine".into())
}
let s: String = only_good_news().into_ok();
println!("{s}");
Sourcepub const fn into_err(self) -> E
๐ฌThis is a nightly-only experimental API. (unwrap_infallible
)
pub const fn into_err(self) -> E
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
fn only_bad_news() -> Result<!, String> {
Err("Oops, it failed".into())
}
let error: String = only_bad_news().into_err();
println!("{error}");
1.0.0 (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
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"));
1.0.0 (const: unstable) ยท Sourcepub fn and_then<U, F>(self, op: F) -> Result<U, E>
pub fn and_then<U, F>(self, op: F) -> 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);
1.0.0 (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
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));
1.0.0 (const: unstable) ยท Sourcepub fn or_else<F, O>(self, op: O) -> Result<T, F>
pub fn or_else<F, O>(self, op: O) -> 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
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));
1.0.0 (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
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);
1.0.0 (const: unstable) ยท 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");
Sourceยงimpl<T, E> Result<&T, E>
impl<T, E> Result<&T, E>
1.59.0 (const: 1.83.0) ยท Sourcepub const fn copied(self) -> Result<T, E>where
T: Copy,
pub const fn copied(self) -> Result<T, E>where
T: Copy,
Maps a Result<&T, E>
to a Result<T, E>
by copying the contents of the
Ok
part.
ยงExamples
let val = 12;
let x: Result<&i32, i32> = Ok(&val);
assert_eq!(x, Ok(&12));
let copied = x.copied();
assert_eq!(copied, Ok(12));
Sourceยงimpl<T, E> Result<&mut T, E>
impl<T, E> Result<&mut T, E>
1.59.0 (const: 1.83.0) ยท Sourcepub const fn copied(self) -> Result<T, E>where
T: Copy,
pub const 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: 1.83.0) ยท Sourcepub const fn transpose(self) -> Option<Result<T, E>>
pub const 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>
1.89.0 (const: 1.89.0) ยท Sourcepub const fn flatten(self) -> Result<T, E>
pub const fn flatten(self) -> Result<T, E>
Converts from Result<Result<T, E>, E>
to Result<T, E>
ยงExamples
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:
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ยง
ยงimpl<T, E> AddAnyAttr for Result<T, E>
impl<T, E> AddAnyAttr for Result<T, E>
ยงtype Output<SomeNewAttr: Attribute> = Result<<T as AddAnyAttr>::Output<SomeNewAttr>, E>
type Output<SomeNewAttr: Attribute> = Result<<T as AddAnyAttr>::Output<SomeNewAttr>, E>
ยงfn add_any_attr<NewAttr>(
self,
attr: NewAttr,
) -> <Result<T, E> as AddAnyAttr>::Output<NewAttr>
fn add_any_attr<NewAttr>( self, attr: NewAttr, ) -> <Result<T, E> as AddAnyAttr>::Output<NewAttr>
ยงimpl<T, E> Archive for Result<T, E>where
T: Archive,
E: Archive,
impl<T, E> Archive for Result<T, E>where
T: Archive,
E: Archive,
ยงtype Archived = ArchivedResult<<T as Archive>::Archived, <E as Archive>::Archived>
type Archived = ArchivedResult<<T as Archive>::Archived, <E as Archive>::Archived>
Sourceยงimpl<'de, T, U, Context> BorrowDecode<'de, Context> for Result<T, U>where
T: BorrowDecode<'de, Context>,
U: BorrowDecode<'de, Context>,
impl<'de, T, U, Context> BorrowDecode<'de, Context> for Result<T, U>where
T: BorrowDecode<'de, Context>,
U: BorrowDecode<'de, Context>,
Sourceยงfn borrow_decode<D>(decoder: &mut D) -> Result<Result<T, U>, DecodeError>where
D: BorrowDecoder<'de, Context = Context>,
fn borrow_decode<D>(decoder: &mut D) -> Result<Result<T, U>, DecodeError>where
D: BorrowDecoder<'de, Context = Context>,
Sourceยงimpl<T, E> Context<T, E> for Result<T, E>
impl<T, E> Context<T, E> for Result<T, E>
Sourceยง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<L, R> From<Either<L, R>> for Result<R, L>
Convert from Either
to Result
with Right => Ok
and Left => Err
.
impl<L, R> From<Either<L, R>> for Result<R, L>
Convert from Either
to Result
with Right => Ok
and Left => Err
.
Sourceยงimpl<L, R> From<Result<R, L>> for Either<L, R>
Convert from Result
to Either
with Ok => Right
and Err => Left
.
impl<L, R> From<Result<R, L>> for Either<L, R>
Convert from Result
to Either
with Ok => Right
and Err => Left
.
1.0.0 ยท 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.
ยงimpl<C, T, E> FromParallelIterator<Result<T, E>> for Result<C, E>
Collect an arbitrary Result
-wrapped collection.
impl<C, T, E> FromParallelIterator<Result<T, E>> for Result<C, E>
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.
ยง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 moreยงimpl<S, T> FromRequest<S> for Result<T, <T as FromRequest<S>>::Rejection>
impl<S, T> FromRequest<S> for Result<T, <T as FromRequest<S>>::Rejection>
ยงtype Rejection = Infallible
type Rejection = Infallible
ยงasync fn from_request(
req: Request<Body>,
state: &S,
) -> Result<Result<T, <T as FromRequest<S>>::Rejection>, <Result<T, <T as FromRequest<S>>::Rejection> as FromRequest<S>>::Rejection>
async fn from_request( req: Request<Body>, state: &S, ) -> Result<Result<T, <T as FromRequest<S>>::Rejection>, <Result<T, <T as FromRequest<S>>::Rejection> as FromRequest<S>>::Rejection>
ยงimpl<S, T> FromRequestParts<S> for Result<T, <T as FromRequestParts<S>>::Rejection>
impl<S, T> FromRequestParts<S> for Result<T, <T as FromRequestParts<S>>::Rejection>
ยงtype Rejection = Infallible
type Rejection = Infallible
ยงasync fn from_request_parts(
parts: &mut Parts,
state: &S,
) -> Result<Result<T, <T as FromRequestParts<S>>::Rejection>, <Result<T, <T as FromRequestParts<S>>::Rejection> as FromRequestParts<S>>::Rejection>
async fn from_request_parts( parts: &mut Parts, state: &S, ) -> Result<Result<T, <T as FromRequestParts<S>>::Rejection>, <Result<T, <T as FromRequestParts<S>>::Rejection> as FromRequestParts<S>>::Rejection>
Sourceยงimpl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Option<Result<T, F>>>where
F: From<E>,
Sourceยงfn from_residual(x: Result<Infallible, E>) -> Poll<Option<Result<T, F>>>
fn from_residual(x: Result<Infallible, E>) -> Poll<Option<Result<T, F>>>
try_trait_v2
)Residual
type. Read moreSourceยงimpl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>where
F: From<E>,
impl<T, E, F> FromResidual<Result<Infallible, E>> for Poll<Result<T, F>>where
F: From<E>,
Sourceยงfn from_residual(x: Result<Infallible, E>) -> Poll<Result<T, F>>
fn from_residual(x: Result<Infallible, E>) -> Poll<Result<T, F>>
try_trait_v2
)Residual
type. Read moreSourceยง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>,
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 moreยงimpl<T, E> InstrumentResult<T> for Result<T, E>where
E: InstrumentError,
impl<T, E> InstrumentResult<T> for Result<T, E>where
E: InstrumentError,
ยงtype Instrumented = <E as InstrumentError>::Instrumented
type Instrumented = <E as InstrumentError>::Instrumented
ยงfn in_current_span(
self,
) -> Result<T, <Result<T, E> as InstrumentResult<T>>::Instrumented>
fn in_current_span( self, ) -> Result<T, <Result<T, E> as InstrumentResult<T>>::Instrumented>
1.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>
1.0.0 ยท 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
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<B, E> IntoMapRequestResult<B> for Result<Request<B>, E>where
E: IntoResponse,
impl<B, E> IntoMapRequestResult<B> for Result<Request<B>, E>where
E: IntoResponse,
ยงimpl<T, E> IntoResponse for Result<T, E>where
T: IntoResponse,
E: IntoResponse,
impl<T, E> IntoResponse for Result<T, E>where
T: IntoResponse,
E: IntoResponse,
ยงfn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
ยงimpl<T> IntoResponse for Result<T, ErrorResponse>where
T: IntoResponse,
impl<T> IntoResponse for Result<T, ErrorResponse>where
T: IntoResponse,
ยงfn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
ยงimpl<M, E> Mountable for Result<M, E>where
M: Mountable,
impl<M, E> Mountable for Result<M, E>where
M: Mountable,
ยงfn insert_before_this(&self, child: &mut dyn Mountable) -> bool
fn insert_before_this(&self, child: &mut dyn Mountable) -> bool
Mountable
type before this one. Returns false
if
this does not actually exist in the UI (for example, ()
).ยงimpl<'a, T> OrPoisoned for Result<MutexGuard<'a, T>, PoisonError<MutexGuard<'a, T>>>
impl<'a, T> OrPoisoned for Result<MutexGuard<'a, T>, PoisonError<MutexGuard<'a, T>>>
ยงtype Inner = MutexGuard<'a, T>
type Inner = MutexGuard<'a, T>
ยงfn or_poisoned(
self,
) -> <Result<MutexGuard<'a, T>, PoisonError<MutexGuard<'a, T>>> as OrPoisoned>::Inner
fn or_poisoned( self, ) -> <Result<MutexGuard<'a, T>, PoisonError<MutexGuard<'a, T>>> as OrPoisoned>::Inner
ยงimpl<'a, T> OrPoisoned for Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>>
impl<'a, T> OrPoisoned for Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>>
ยงtype Inner = RwLockReadGuard<'a, T>
type Inner = RwLockReadGuard<'a, T>
ยงfn or_poisoned(
self,
) -> <Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>> as OrPoisoned>::Inner
fn or_poisoned( self, ) -> <Result<RwLockReadGuard<'a, T>, PoisonError<RwLockReadGuard<'a, T>>> as OrPoisoned>::Inner
ยงimpl<'a, T> OrPoisoned for Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>>
impl<'a, T> OrPoisoned for Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>>
ยงtype Inner = RwLockWriteGuard<'a, T>
type Inner = RwLockWriteGuard<'a, T>
ยงfn or_poisoned(
self,
) -> <Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>> as OrPoisoned>::Inner
fn or_poisoned( self, ) -> <Result<RwLockWriteGuard<'a, T>, PoisonError<RwLockWriteGuard<'a, T>>> as OrPoisoned>::Inner
1.0.0 ยท Sourceยงimpl<T, E> Ord for Result<T, E>
impl<T, E> Ord for Result<T, E>
1.21.0 ยท Sourceยงfn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
1.0.0 ยท Sourceยงimpl<T, E> PartialOrd for Result<T, E>where
T: PartialOrd,
E: PartialOrd,
impl<T, E> PartialOrd for Result<T, E>where
T: PartialOrd,
E: PartialOrd,
ยงimpl<B, E> Policy<B, E> for Result<Action, E>where
E: Clone,
impl<B, E> Policy<B, E> for Result<Action, E>where
E: Clone,
ยงfn redirect(&mut self, _: &Attempt<'_>) -> Result<Action, E>
fn redirect(&mut self, _: &Attempt<'_>) -> Result<Action, E>
3xx
). Read moreยงfn on_request(&mut self, _request: &mut Request<B>)
fn on_request(&mut self, _request: &mut Request<B>)
ยงfn clone_body(&self, _body: &B) -> Option<B>
fn clone_body(&self, _body: &B) -> Option<B>
1.16.0 ยท Sourceยงimpl<T, U, E> Product<Result<U, E>> for Result<T, E>where
T: Product<U>,
impl<T, U, E> Product<Result<U, E>> for Result<T, E>where
T: Product<U>,
Sourceยงfn product<I>(iter: I) -> Result<T, E>
fn product<I>(iter: I) -> Result<T, 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 product of all elements is returned.
ยงExamples
This multiplies each number in a vector of strings,
if a string could not be parsed the operation returns Err
:
let nums = vec!["5", "10", "1", "2"];
let total: Result<usize, _> = nums.iter().map(|w| w.parse::<usize>()).product();
assert_eq!(total, Ok(100));
let nums = vec!["5", "10", "one", "2"];
let total: Result<usize, _> = nums.iter().map(|w| w.parse::<usize>()).product();
assert!(total.is_err());
ยงimpl<T, E> Render for Result<T, E>
impl<T, E> Render for Result<T, E>
ยงimpl<T, E> RenderHtml for Result<T, E>
impl<T, E> RenderHtml for Result<T, E>
ยงconst MIN_LENGTH: usize = T::MIN_LENGTH
const MIN_LENGTH: usize = T::MIN_LENGTH
ยงtype AsyncOutput = Result<<T as RenderHtml>::AsyncOutput, E>
type AsyncOutput = Result<<T as RenderHtml>::AsyncOutput, E>
ยงtype Owned = Result<<T as RenderHtml>::Owned, E>
type Owned = Result<<T as RenderHtml>::Owned, E>
'static
.ยงfn dry_resolve(&mut self)
fn dry_resolve(&mut self)
ยงasync fn resolve(self) -> <Result<T, E> as RenderHtml>::AsyncOutput
async fn resolve(self) -> <Result<T, E> as RenderHtml>::AsyncOutput
ยงfn to_html_with_buf(
self,
buf: &mut String,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
)
fn to_html_with_buf( self, buf: &mut String, position: &mut Position, escape: bool, mark_branches: bool, extra_attrs: Vec<AnyAttribute>, )
ยงfn to_html_async_with_buf<const OUT_OF_ORDER: bool>(
self,
buf: &mut StreamBuilder,
position: &mut Position,
escape: bool,
mark_branches: bool,
extra_attrs: Vec<AnyAttribute>,
)
fn to_html_async_with_buf<const OUT_OF_ORDER: bool>( self, buf: &mut StreamBuilder, position: &mut Position, escape: bool, mark_branches: bool, extra_attrs: Vec<AnyAttribute>, )
ยงfn hydrate<const FROM_SERVER: bool>(
self,
cursor: &Cursor,
position: &PositionState,
) -> <Result<T, E> as Render>::State
fn hydrate<const FROM_SERVER: bool>( self, cursor: &Cursor, position: &PositionState, ) -> <Result<T, E> as Render>::State
ยงasync fn hydrate_async(
self,
cursor: &Cursor,
position: &PositionState,
) -> <Result<T, E> as Render>::State
async fn hydrate_async( self, cursor: &Cursor, position: &PositionState, ) -> <Result<T, E> as Render>::State
ยงfn into_owned(self) -> <Result<T, E> as RenderHtml>::Owned
fn into_owned(self) -> <Result<T, E> as RenderHtml>::Owned
'static
.ยงconst EXISTS: bool = true
const EXISTS: bool = true
ยงfn to_html_branching(self) -> Stringwhere
Self: Sized,
fn to_html_branching(self) -> Stringwhere
Self: Sized,
ยงfn to_html_stream_in_order(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_in_order(self) -> StreamBuilderwhere
Self: Sized,
ยงfn to_html_stream_in_order_branching(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_in_order_branching(self) -> StreamBuilderwhere
Self: Sized,
ยงfn to_html_stream_out_of_order(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_out_of_order(self) -> StreamBuilderwhere
Self: Sized,
ยงfn to_html_stream_out_of_order_branching(self) -> StreamBuilderwhere
Self: Sized,
fn to_html_stream_out_of_order_branching(self) -> StreamBuilderwhere
Self: Sized,
ยงfn hydrate_from<const FROM_SERVER: bool>(self, el: &Element) -> Self::Statewhere
Self: Sized,
fn hydrate_from<const FROM_SERVER: bool>(self, el: &Element) -> Self::Statewhere
Self: Sized,
RenderHtml::hydrate
, beginning at the given element.ยงfn hydrate_from_position<const FROM_SERVER: bool>(
self,
el: &Element,
position: Position,
) -> Self::Statewhere
Self: Sized,
fn hydrate_from_position<const FROM_SERVER: bool>(
self,
el: &Element,
position: Position,
) -> Self::Statewhere
Self: Sized,
RenderHtml::hydrate
, beginning at the given element and position.Sourceยงimpl<T, E> Residual<T> for Result<Infallible, E>
impl<T, E> Residual<T> for Result<Infallible, E>
ยงimpl<T> ResultDataError<T> for Result<T, DataError>
impl<T> ResultDataError<T> for Result<T, DataError>
ยงfn allow_identifier_not_found(self) -> Result<Option<T>, DataError>
fn allow_identifier_not_found(self) -> Result<Option<T>, DataError>
DataErrorKind::IdentifierNotFound
], and returns None
in that case.Sourceยงimpl<T, E> ReturnWasmAbi for Result<T, E>
impl<T, E> ReturnWasmAbi for Result<T, E>
Sourceยงfn return_abi(self) -> <Result<T, E> as ReturnWasmAbi>::Abi
fn return_abi(self) -> <Result<T, E> as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi
, except that it may throw and never
return in the case of Err
.ยงimpl<T, E, S> Serialize<S> for Result<T, E>where
T: Serialize<S>,
E: Serialize<S>,
S: Fallible + ?Sized,
impl<T, E, S> Serialize<S> for Result<T, E>where
T: Serialize<S>,
E: Serialize<S>,
S: Fallible + ?Sized,
Sourceยงimpl<T, E> Serialize for Result<T, E>
impl<T, E> Serialize for Result<T, E>
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>
fn sum<I>(iter: I) -> Result<T, 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 f = |&x: &i32| if x < 0 { Err("Negative element found") } else { Ok(x) };
let v = vec![1, 2];
let res: Result<i32, _> = v.iter().map(f).sum();
assert_eq!(res, Ok(3));
let v = vec![1, -2];
let res: Result<i32, _> = v.iter().map(f).sum();
assert_eq!(res, Err("Negative element found"));
1.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,
ยงimpl<T, E> TestTermination for Result<T, E>
impl<T, E> TestTermination for Result<T, E>
fn is_success(&self) -> bool
Sourceยงimpl<T, E> Try for Result<T, E>
impl<T, E> Try for Result<T, E>
Sourceยงtype Output = T
type Output = T
try_trait_v2
)?
when not short-circuiting.Sourceยงtype Residual = Result<Infallible, E>
type Residual = Result<Infallible, E>
try_trait_v2
)FromResidual::from_residual
as part of ?
when short-circuiting. Read moreSourceยง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 moreSourceยง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 moreยงimpl<T, E> TryWriteable for Result<T, E>where
T: Writeable,
E: Writeable + Clone,
impl<T, E> TryWriteable for Result<T, E>where
T: Writeable,
E: Writeable + Clone,
type Error = E
ยงfn try_write_to<W>(
&self,
sink: &mut W,
) -> Result<Result<(), <Result<T, E> as TryWriteable>::Error>, Error>
fn try_write_to<W>( &self, sink: &mut W, ) -> Result<Result<(), <Result<T, E> as TryWriteable>::Error>, Error>
ยงfn try_write_to_parts<S>(
&self,
sink: &mut S,
) -> Result<Result<(), <Result<T, E> as TryWriteable>::Error>, Error>where
S: PartsWrite + ?Sized,
fn try_write_to_parts<S>(
&self,
sink: &mut S,
) -> Result<Result<(), <Result<T, E> as TryWriteable>::Error>, Error>where
S: PartsWrite + ?Sized,
ยงfn writeable_length_hint(&self) -> LengthHint
fn writeable_length_hint(&self) -> LengthHint
Sourceยงimpl<T, E> UnwrapThrowExt<T> for Result<T, E>where
E: Debug,
impl<T, E> UnwrapThrowExt<T> for Result<T, E>where
E: Debug,
Sourceยงfn unwrap_throw(self) -> T
fn unwrap_throw(self) -> T
Option
or Result
, but instead of panicking on failure,
throw an exception to JavaScript.Sourceยงfn expect_throw(self, message: &str) -> T
fn expect_throw(self, message: &str) -> T
T
value, or throw an error to JS with the
given message if the T
value is unavailable (e.g. an Option<T>
is
None
).Sourceยงimpl<T> WasmAbi for Result<T, u32>
impl<T> WasmAbi for Result<T, u32>
Sourceยงimpl<T, E> WrapErr<T, E> for Result<T, E>
impl<T, E> WrapErr<T, E> for Result<T, E>
Sourceยงfn wrap_err<D>(self, msg: D) -> Result<T, Report>
fn wrap_err<D>(self, msg: D) -> Result<T, Report>
Sourceยงfn wrap_err_with<D, F>(self, msg: F) -> Result<T, Report>
fn wrap_err_with<D, F>(self, msg: F) -> Result<T, Report>
impl<T, E> Copy for Result<T, E>
impl<T, E> Eq for Result<T, E>
impl<T, U, E> FromStream<Result<T, E>> for Result<U, E>where
U: FromStream<T>,
impl<T, E> StructuralPartialEq for Result<T, E>
impl<T, E> UseCloned for Result<T, E>
Auto Trait Implementationsยง
impl<T, E> Freeze for Result<T, E>
impl<T, E> RefUnwindSafe for Result<T, E>where
T: RefUnwindSafe,
E: RefUnwindSafe,
impl<T, E> Send for Result<T, E>
impl<T, E> Sync for Result<T, E>
impl<T, E> Unpin for Result<T, E>
impl<T, E> UnwindSafe for Result<T, E>where
T: UnwindSafe,
E: UnwindSafe,
Blanket Implementationsยง
Sourceยงimpl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Sourceยงfn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Sourceยงfn adapt_into(self) -> D
fn adapt_into(self) -> D
ยงimpl<T> ArchivePointee for T
impl<T> ArchivePointee for T
ยงtype ArchivedMetadata = ()
type ArchivedMetadata = ()
ยงfn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
ยงimpl<T> ArchiveUnsized for Twhere
T: Archive,
impl<T> ArchiveUnsized for Twhere
T: Archive,
ยงtype Archived = <T as Archive>::Archived
type Archived = <T as Archive>::Archived
Archive
, it may be unsized. Read moreยงtype MetadataResolver = ()
type MetadataResolver = ()
ยงunsafe fn resolve_metadata(
&self,
_: usize,
_: <T as ArchiveUnsized>::MetadataResolver,
_: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata,
)
unsafe fn resolve_metadata( &self, _: usize, _: <T as ArchiveUnsized>::MetadataResolver, _: *mut <<T as ArchiveUnsized>::Archived as ArchivePointee>::ArchivedMetadata, )
Sourceยงimpl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Sourceยงfn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Sourceยงimpl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Sourceยงfn arrays_into(self) -> C
fn arrays_into(self) -> C
ยงimpl<V, Key, Sig, T> BindAttribute<Key, Sig, T> for Vwhere
V: AddAnyAttr,
Key: AttributeKey,
Sig: IntoSplitSignal<Value = T>,
T: FromEventTarget + AttributeValue + PartialEq + Sync + 'static,
Signal<BoolOrT<T>>: IntoProperty,
<Sig as IntoSplitSignal>::Read: Get<Value = T> + Send + Sync + Clone + 'static,
<Sig as IntoSplitSignal>::Write: Send + Clone + 'static,
Element: GetValue<T>,
impl<V, Key, Sig, T> BindAttribute<Key, Sig, T> for Vwhere
V: AddAnyAttr,
Key: AttributeKey,
Sig: IntoSplitSignal<Value = T>,
T: FromEventTarget + AttributeValue + PartialEq + Sync + 'static,
Signal<BoolOrT<T>>: IntoProperty,
<Sig as IntoSplitSignal>::Read: Get<Value = T> + Send + Sync + Clone + 'static,
<Sig as IntoSplitSignal>::Write: Send + Clone + 'static,
Element: GetValue<T>,
ยงtype Output = <V as AddAnyAttr>::Output<Bind<Key, T, <Sig as IntoSplitSignal>::Read, <Sig as IntoSplitSignal>::Write>>
type Output = <V as AddAnyAttr>::Output<Bind<Key, T, <Sig as IntoSplitSignal>::Read, <Sig as IntoSplitSignal>::Write>>
ยงfn bind(
self,
key: Key,
signal: Sig,
) -> <V as BindAttribute<Key, Sig, T>>::Output
fn bind( self, key: Key, signal: Sig, ) -> <V as BindAttribute<Key, Sig, T>>::Output
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
ยงimpl<T> CallHasher for T
impl<T> CallHasher for T
Sourceยงimpl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Sourceยงtype Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters
when converting.Sourceยงfn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
ยงimpl<It, V> CollectView for Itwhere
It: IntoIterator<Item = V>,
V: IntoView,
impl<It, V> CollectView for Itwhere
It: IntoIterator<Item = V>,
V: IntoView,
ยงfn collect_view(self) -> Vec<<It as CollectView>::View>
fn collect_view(self) -> Vec<<It as CollectView>::View>
ยงimpl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Sourceยงimpl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Sourceยงfn components_from(colors: C) -> T
fn components_from(colors: C) -> T
ยงimpl<T, K, V> CustomAttribute<K, V> for Twhere
T: AddAnyAttr,
K: CustomAttributeKey,
V: AttributeValue,
impl<T, K, V> CustomAttribute<K, V> for Twhere
T: AddAnyAttr,
K: CustomAttributeKey,
V: AttributeValue,
ยงimpl<F, W, T, D> Deserialize<With<T, W>, D> for F
impl<F, W, T, D> Deserialize<With<T, W>, D> for F
ยงfn deserialize(
&self,
deserializer: &mut D,
) -> Result<With<T, W>, <D as Fallible>::Error>
fn deserialize( &self, deserializer: &mut D, ) -> Result<With<T, W>, <D as Fallible>::Error>
ยงimpl<V, T, P, D> DirectiveAttribute<T, P, D> for Vwhere
V: AddAnyAttr,
D: IntoDirective<T, P>,
P: Clone + 'static,
T: 'static,
impl<V, T, P, D> DirectiveAttribute<T, P, D> for Vwhere
V: AddAnyAttr,
D: IntoDirective<T, P>,
P: Clone + 'static,
T: 'static,
ยงtype Output = <V as AddAnyAttr>::Output<Directive<T, D, P>>
type Output = <V as AddAnyAttr>::Output<Directive<T, D, P>>
ยงfn directive(
self,
handler: D,
param: P,
) -> <V as DirectiveAttribute<T, P, D>>::Output
fn directive( self, handler: D, param: P, ) -> <V as DirectiveAttribute<T, P, D>>::Output
ยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
ยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.ยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.ยง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.ยง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.ยงimpl<T> DowncastSend for T
impl<T> DowncastSend for T
ยงimpl<T> DowncastSync for T
impl<T> DowncastSync for T
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Sourceยงimpl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Sourceยงfn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle
.ยงimpl<T> FromFormData for Twhere
T: DeserializeOwned,
impl<T> FromFormData for Twhere
T: DeserializeOwned,
ยงfn from_event(ev: &Event) -> Result<T, FromFormDataError>
fn from_event(ev: &Event) -> Result<T, FromFormDataError>
submit
event.ยงfn from_form_data(form_data: &FormData) -> Result<T, Error>
fn from_form_data(form_data: &FormData) -> Result<T, Error>
ยงimpl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
ยงtype Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
ยงfn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Sourceยงimpl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Sourceยงfn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other
into Self
, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
ยงfn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
ยงfn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
tower::Layer
] to the handler. Read moreยงfn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service
] by providing the stateยงimpl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
ยงfn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service
] and no state.ยงfn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService
and no state. Read moreยงfn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
MakeService
which stores information
about the incoming connection and has no state. Read moreSourceยงimpl<T> Hexable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
impl<T> Hexable for Twhere
T: Serialize + for<'de> Deserialize<'de>,
ยงimpl<T> Instrument for T
impl<T> Instrument for T
ยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงimpl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Sourceยงfn into_angle(self) -> U
fn into_angle(self) -> U
T
.ยงimpl<T> IntoAny for Twhere
T: Send + RenderHtml,
impl<T> IntoAny for Twhere
T: Send + RenderHtml,
Sourceยงimpl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Sourceยงtype Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters
when converting.Sourceยงfn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self
into C
, using the provided parameters.Sourceยงimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Sourceยงfn into_color(self) -> U
fn into_color(self) -> U
Sourceยงimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Sourceยงfn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreยงimpl<T> IntoMaybeErased for Twhere
T: RenderHtml,
impl<T> IntoMaybeErased for Twhere
T: RenderHtml,
ยงfn into_maybe_erased(self) -> <T as IntoMaybeErased>::Output
fn into_maybe_erased(self) -> <T as IntoMaybeErased>::Output
ยงimpl<'data, I> IntoParallelRefIterator<'data> for I
impl<'data, I> IntoParallelRefIterator<'data> for I
ยง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.ยง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 moreยงimpl<T> IntoRender for Twhere
T: Render,
impl<T> IntoRender for Twhere
T: Render,
ยงfn into_render(self) -> <T as IntoRender>::Output
fn into_render(self) -> <T as IntoRender>::Output
Sourceยงimpl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Sourceยงfn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self
into T
, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Pointable for T
impl<T> Pointable for T
ยงimpl<T> Pointee for T
impl<T> Pointee for T
ยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
ยงimpl<T> SerializableKey for T
impl<T> SerializableKey for T
ยงimpl<T, S> SerializeUnsized<S> for Twhere
T: Serialize<S>,
S: Serializer + ?Sized,
impl<T, S> SerializeUnsized<S> for Twhere
T: Serialize<S>,
S: Serializer + ?Sized,
ยงfn serialize_unsized(
&self,
serializer: &mut S,
) -> Result<usize, <S as Fallible>::Error>
fn serialize_unsized( &self, serializer: &mut S, ) -> Result<usize, <S as Fallible>::Error>
ยงfn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>
fn serialize_metadata(&self, _: &mut S) -> Result<(), <S as Fallible>::Error>
ยงimpl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
ยงfn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
ยงfn into_taken(self) -> T
fn into_taken(self) -> T
Sourceยงimpl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Sourceยงtype Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors
fails to cast.Sourceยงfn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Sourceยงimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Sourceยงfn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds
error is returned which contains
the unclamped color. Read more