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§
Source§impl<T> ClientResult<T>
impl<T> ClientResult<T>
Sourcepub fn new_err(errors: Vec<ClientError>) -> Self
pub fn new_err(errors: Vec<ClientError>) -> Self
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.
Sourcepub fn new_ok_and_err(value: T, errors: Vec<ClientError>) -> Self
pub fn new_ok_and_err(value: T, errors: Vec<ClientError>) -> Self
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.
Sourcepub fn errors(&self) -> &[ClientError]
pub fn errors(&self) -> &[ClientError]
Returns the errors list.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Returns true if there are errors.
Sourcepub 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.
Sourcepub fn into_errors(self) -> Vec<ClientError>
pub fn into_errors(self) -> Vec<ClientError>
Consume the result and return the errors list.
Sourcepub 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.
Sourcepub 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.