ClientResult

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>

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>

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>

Creates a result containing errors and a value to rescue.

This method should only be used when there are both errors and a value.

pub fn value(&self) -> Option<&T>

Returns the successful value if there is one.

pub fn errors(&self) -> &[ClientError]

Returns the errors list.

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>

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,

Maps the successful value to another value, cloning the errors list.

pub fn has_value(&self) -> bool

Returns true if there is a successful value.

pub fn has_errors(&self) -> bool

Returns true if there are errors.

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>

Consume the result and return the errors list.

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>

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>>

Consume the result to convert it into a standard Result.

Trait Implementations§

§

impl<T> Clone for ClientResult<T>
where T: Clone,

§

fn clone(&self) -> ClientResult<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<T> Debug for ClientResult<T>
where T: Debug,

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl<T> From<ClientError> for ClientResult<T>

§

fn from(error: ClientError) -> ClientResult<T>

Converts to this type from the input type.
§

impl<T> From<Result<T, ClientError>> for ClientResult<T>

§

fn from(result: Result<T, ClientError>) -> ClientResult<T>

Converts to this type from the input type.
§

impl<T> From<Result<T, Vec<ClientError>>> for ClientResult<T>

§

fn from(result: Result<T, Vec<ClientError>>) -> ClientResult<T>

Converts to this type from the input type.
§

impl<T> TryFrom<(Option<T>, Vec<ClientError>)> for ClientResult<T>

§

type Error = ClientError

The type returned in the event of a conversion error.
§

fn try_from( value: (Option<T>, Vec<ClientError>), ) -> Result<ClientResult<T>, <ClientResult<T> as TryFrom<(Option<T>, Vec<ClientError>)>>::Error>

Performs the conversion.

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
where T: 'static + Debug + ?Sized,

§

fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

§

fn ref_cast_type_id(&self) -> TypeId
where Self: 'static,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert 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>

Convert 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)

Convert &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)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WidgetActionTrait for T
where T: 'static + Clone + Debug + Send + Sync + ?Sized,

§

fn ref_cast_type_id(&self) -> TypeId

§

fn box_clone(&self) -> Box<dyn WidgetActionTrait>

§

fn debug_fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> PlatformSend for T
where T: PlatformSendInner,

§

impl<T> PlatformSendInner for T
where T: Send,