Struct wooting_analog_common::SDKResult
source · [−]pub struct SDKResult<T>(pub Result<T, WootingAnalogResult>);
Tuple Fields
0: Result<T, WootingAnalogResult>
Methods from Deref<Target = Result<T, WootingAnalogResult>>
sourcepub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool
🔬 This is a nightly-only experimental API. (is_some_with
)
pub fn is_ok_and(&self, f: impl FnOnce(&T) -> bool) -> bool
is_some_with
)Returns true
if the result is Ok
and the value inside of it matches a predicate.
Examples
#![feature(is_some_with)]
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.is_ok_and(|&x| x > 1), true);
let x: Result<u32, &str> = Ok(0);
assert_eq!(x.is_ok_and(|&x| x > 1), false);
let x: Result<u32, &str> = Err("hey");
assert_eq!(x.is_ok_and(|&x| x > 1), false);
sourcepub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool
🔬 This is a nightly-only experimental API. (is_some_with
)
pub fn is_err_and(&self, f: impl FnOnce(&E) -> bool) -> bool
is_some_with
)Returns true
if the result is Err
and the value inside of it matches a predicate.
Examples
#![feature(is_some_with)]
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);
1.0.0 · sourcepub fn as_ref(&self) -> Result<&T, &E>
pub fn as_ref(&self) -> Result<&T, &E>
Converts from &Result<T, E>
to Result<&T, &E>
.
Produces a new Result
, containing a reference
into the original, leaving the original in place.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.as_ref(), Ok(&2));
let x: Result<u32, &str> = Err("Error");
assert_eq!(x.as_ref(), Err(&"Error"));
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.0.0 · sourcepub fn iter(&self) -> Iter<'_, T>
pub fn iter(&self) -> Iter<'_, T>
Returns an iterator over the possibly contained value.
The iterator yields one value if the result is Result::Ok
, otherwise none.
Examples
Basic usage:
let x: Result<u32, &str> = Ok(7);
assert_eq!(x.iter().next(), Some(&7));
let x: Result<u32, &str> = Err("nothing!");
assert_eq!(x.iter().next(), None);
sourcepub fn contains<U>(&self, x: &U) -> bool where
U: PartialEq<T>,
🔬 This is a nightly-only experimental API. (option_result_contains
)
pub fn contains<U>(&self, x: &U) -> bool where
U: PartialEq<T>,
option_result_contains
)Returns true
if the result is an Ok
value containing the given value.
Examples
#![feature(option_result_contains)]
let x: Result<u32, &str> = Ok(2);
assert_eq!(x.contains(&2), true);
let x: Result<u32, &str> = Ok(3);
assert_eq!(x.contains(&2), false);
let x: Result<u32, &str> = Err("Some error message");
assert_eq!(x.contains(&2), false);
sourcepub fn contains_err<F>(&self, f: &F) -> bool where
F: PartialEq<E>,
🔬 This is a nightly-only experimental API. (result_contains_err
)
pub fn contains_err<F>(&self, f: &F) -> bool where
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);
Trait Implementations
sourceimpl<T> From<Result<T, WootingAnalogResult>> for SDKResult<T>
impl<T> From<Result<T, WootingAnalogResult>> for SDKResult<T>
sourcefn from(ptr: Result<T, WootingAnalogResult>) -> Self
fn from(ptr: Result<T, WootingAnalogResult>) -> Self
Converts to this type from the input type.
sourceimpl From<WootingAnalogResult> for SDKResult<()>
impl From<WootingAnalogResult> for SDKResult<()>
sourcefn from(res: WootingAnalogResult) -> Self
fn from(res: WootingAnalogResult) -> Self
Converts to this type from the input type.
sourceimpl<T> Into<Result<T, WootingAnalogResult>> for SDKResult<T>
impl<T> Into<Result<T, WootingAnalogResult>> for SDKResult<T>
sourcefn into(self) -> Result<T, WootingAnalogResult>
fn into(self) -> Result<T, WootingAnalogResult>
Converts this type into the (usually inferred) input type.
sourceimpl Into<WootingAnalogResult> for SDKResult<()>
impl Into<WootingAnalogResult> for SDKResult<()>
sourcefn into(self) -> WootingAnalogResult
fn into(self) -> WootingAnalogResult
Converts this type into the (usually inferred) input type.
Auto Trait Implementations
impl<T> RefUnwindSafe for SDKResult<T> where
T: RefUnwindSafe,
impl<T> Send for SDKResult<T> where
T: Send,
impl<T> Sync for SDKResult<T> where
T: Sync,
impl<T> Unpin for SDKResult<T> where
T: Unpin,
impl<T> UnwindSafe for SDKResult<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more