Struct ClientResult
pub struct ClientResult<T> { /* private fields */ }Expand description
The outcome of a client operation.
Different from the standard Result, this one may contain more than one error. And at the same time, even if an error ocurrs, there may be a value to rescue.
It would be mistake if this contains no value and no errors at the same time. This is taken care on creation time, and it can’t be modified afterwards.
Implementations§
§impl<T> ClientResult<T>
impl<T> ClientResult<T>
pub fn new_ok(value: T) -> ClientResult<T>
pub fn new_ok(value: T) -> ClientResult<T>
Creates a result containing a successful value and no errors.
pub fn new_err(errors: Vec<ClientError>) -> ClientResult<T>
pub fn new_err(errors: Vec<ClientError>) -> ClientResult<T>
Creates a result containing errors and no value to rescue.
The errors list should be non empty. If it’s empty a default error will be added to avoid the invariant of having no value and no errors at the same time.
pub fn new_ok_and_err(value: T, errors: Vec<ClientError>) -> ClientResult<T>
pub fn new_ok_and_err(value: T, errors: Vec<ClientError>) -> ClientResult<T>
Creates a result containing errors and a value to rescue.
This method should only be used when there are both errors and a value.
- If there are no errors, use ClientResult::new_ok instead.
- Similar to ClientResult::new_err, if the errors list is empty, a default error will be added.
pub fn errors(&self) -> &[ClientError]
pub fn errors(&self) -> &[ClientError]
Returns the errors list.
pub fn value_and_errors(&self) -> (Option<&T>, &[ClientError])
pub fn value_and_errors(&self) -> (Option<&T>, &[ClientError])
Returns the successful value and the errors list.
pub fn new_unchecked(
value: Option<T>,
errors: Vec<ClientError>,
) -> ClientResult<T>
pub fn new_unchecked( value: Option<T>, errors: Vec<ClientError>, ) -> ClientResult<T>
Creates a result with the given value and errors without checking the invariant of having at least one of them.
Warning: The main purpose of this method is to construct ClientResults
from already existing ClientResults that are known to be valid. Using
this without caution may lead to invalid states and panic at runtime.
pub fn map_value<'t, U>(&'t self, f: impl FnOnce(&'t T) -> U) -> ClientResult<U>where
U: 't,
pub fn map_value<'t, U>(&'t self, f: impl FnOnce(&'t T) -> U) -> ClientResult<U>where
U: 't,
Maps the successful value to another value, cloning the errors list.
pub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if there are errors.
pub fn into_value(self) -> Option<T>
pub fn into_value(self) -> Option<T>
Consume the result and return the successful value if there is one.
pub fn into_errors(self) -> Vec<ClientError>
pub fn into_errors(self) -> Vec<ClientError>
Consume the result and return the errors list.
pub fn into_value_and_errors(self) -> (Option<T>, Vec<ClientError>)
pub fn into_value_and_errors(self) -> (Option<T>, Vec<ClientError>)
Consume the result and return the successful value and the errors list.
pub fn try_from_value_and_errors(
value: Option<T>,
errors: Vec<ClientError>,
) -> Result<ClientResult<T>, ClientError>
pub fn try_from_value_and_errors( value: Option<T>, errors: Vec<ClientError>, ) -> Result<ClientResult<T>, ClientError>
Crates a ClientResult from an optional value and a list of errors,
failing if both are empty (as it would violate the invariant).
The Err case will contain a default ClientError indicating that no value
nor errors were provided. You can forward this error into ClientResult::new_err
to construct a fallback result, but the error message is addressed to devs, not users.
This method is essentially the inverse of ClientResult::into_value_and_errors.
This method can be used through the standard TryFrom trait as well,
when you have a tuple of (Option<T>, Vec<ClientError>), either by calling
try_from or try_into.
pub fn into_result(self) -> Result<T, Vec<ClientError>>
pub fn into_result(self) -> Result<T, Vec<ClientError>>
Consume the result to convert it into a standard Result.
Trait Implementations§
§impl<T> Clone for ClientResult<T>where
T: Clone,
impl<T> Clone for ClientResult<T>where
T: Clone,
§fn clone(&self) -> ClientResult<T>
fn clone(&self) -> ClientResult<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl<T> Debug for ClientResult<T>where
T: Debug,
impl<T> Debug for ClientResult<T>where
T: Debug,
§impl<T> From<ClientError> for ClientResult<T>
impl<T> From<ClientError> for ClientResult<T>
§fn from(error: ClientError) -> ClientResult<T>
fn from(error: ClientError) -> ClientResult<T>
§impl<T> From<Result<T, ClientError>> for ClientResult<T>
impl<T> From<Result<T, ClientError>> for ClientResult<T>
§fn from(result: Result<T, ClientError>) -> ClientResult<T>
fn from(result: Result<T, ClientError>) -> ClientResult<T>
§impl<T> From<Result<T, Vec<ClientError>>> for ClientResult<T>
impl<T> From<Result<T, Vec<ClientError>>> for ClientResult<T>
§fn from(result: Result<T, Vec<ClientError>>) -> ClientResult<T>
fn from(result: Result<T, Vec<ClientError>>) -> ClientResult<T>
§impl<T> TryFrom<(Option<T>, Vec<ClientError>)> for ClientResult<T>
impl<T> TryFrom<(Option<T>, Vec<ClientError>)> for ClientResult<T>
§type Error = ClientError
type Error = ClientError
§fn try_from(
value: (Option<T>, Vec<ClientError>),
) -> Result<ClientResult<T>, <ClientResult<T> as TryFrom<(Option<T>, Vec<ClientError>)>>::Error>
fn try_from( value: (Option<T>, Vec<ClientError>), ) -> Result<ClientResult<T>, <ClientResult<T> as TryFrom<(Option<T>, Vec<ClientError>)>>::Error>
Auto Trait Implementations§
impl<T> Freeze for ClientResult<T>where
T: Freeze,
impl<T> !RefUnwindSafe for ClientResult<T>
impl<T> Send for ClientResult<T>where
T: Send,
impl<T> Sync for ClientResult<T>where
T: Sync,
impl<T> Unpin for ClientResult<T>where
T: Unpin,
impl<T> !UnwindSafe for ClientResult<T>
Blanket Implementations§
§impl<T> ActionTrait for T
impl<T> ActionTrait for T
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>. Box<dyn Any> can
then be further downcast into Box<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>. Rc<Any> 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.