Struct Response

Source
pub struct Response<Res> {
    pub inner: Result<Res, Error>,
    pub task_id: TaskId,
    pub attempt: Attempt,
    /* private fields */
}
Expand description

A generic Response struct that wraps the result of a task, containing the outcome (Ok or Err), task metadata such as task_id, attempt, and an internal marker field for future extensions.

§Type Parameters

  • Res: The successful result type of the response.

§Fields

  • inner: A Result that holds either the success value of type Res or an Error on failure.
  • task_id: A TaskId representing the unique identifier for the task.
  • attempt: An Attempt representing how many attempts were made to complete the task.
  • _priv: A private marker field to prevent external construction of the Response.

Fields§

§inner: Result<Res, Error>

The result from a task

§task_id: TaskId

The task id

§attempt: Attempt

The current attempt

Implementations§

Source§

impl<Res> Response<Res>

Source

pub fn new(inner: Result<Res, Error>, task_id: TaskId, attempt: Attempt) -> Self

Creates a new Response instance.

§Arguments
  • inner: A Result holding either a successful response of type Res or an Error.
  • task_id: A TaskId representing the unique identifier for the task.
  • attempt: The attempt count when creating this response.
§Returns

A new Response instance.

Source

pub fn success(res: Res, task_id: TaskId, attempt: Attempt) -> Self

Constructs a successful Response.

§Arguments
  • res: The success value of type Res.
  • task_id: A TaskId representing the unique identifier for the task.
  • attempt: The attempt count when creating this response.
§Returns

A Response instance containing the success value.

Source

pub fn failure(error: Error, task_id: TaskId, attempt: Attempt) -> Self

Constructs a failed Response.

§Arguments
  • error: The Error that occurred.
  • task_id: A TaskId representing the unique identifier for the task.
  • attempt: The attempt count when creating this response.
§Returns

A Response instance containing the error.

Source

pub fn is_success(&self) -> bool

Checks if the Response contains a success (Ok).

§Returns

true if the Response is successful, false otherwise.

Source

pub fn is_failure(&self) -> bool

Checks if the Response contains a failure (Err).

§Returns

true if the Response is a failure, false otherwise.

Source

pub fn map<F, T>(&self, f: F) -> Response<T>
where F: FnOnce(&Res) -> T,

Maps the success value (Res) of the Response to another type using the provided function.

§Arguments
  • f: A function that takes a reference to the success value and returns a new value of type T.
§Returns

A new Response with the transformed success value or the same error.

§Type Parameters
  • F: A function or closure that takes a reference to a value of type Res and returns a value of type T.
  • T: The new type of the success value after mapping.

Trait Implementations§

Source§

impl<Res: Clone> Clone for Response<Res>

Source§

fn clone(&self) -> Response<Res>

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

impl<Res: Debug> Debug for Response<Res>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<Res> Freeze for Response<Res>
where Res: Freeze,

§

impl<Res> !RefUnwindSafe for Response<Res>

§

impl<Res> Send for Response<Res>
where Res: Send,

§

impl<Res> Sync for Response<Res>
where Res: Sync,

§

impl<Res> Unpin for Response<Res>
where Res: Unpin,

§

impl<Res> !UnwindSafe for Response<Res>

Blanket Implementations§

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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.
Source§

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

Source§

fn vzip(self) -> V