pub trait HasPayload {
    type Payload: Payload;

    // Required methods
    fn payload_mut(&mut self) -> &mut Self::Payload;
    fn payload_ref(&self) -> &Self::Payload;

    // Provided method
    fn with_payload_mut<F>(self, f: F) -> Self
       where Self: Sized,
             F: FnOnce(&mut Self::Payload) { ... }
}
Expand description

Represents types having payload inside.

This trait is something between DerefMut and BorrowMut — it allows only one implementation per type (the output type is associated, not generic), has implementations for all types P such P: Payload, but has no magic compiler support like DerefMut does nor does it require any laws about Eq, Ord and Hash as BorrowMut does.

Also the output type is bounded by the Payload trait.

This trait is mostly used to implement payload setters (on both payloads & requests), so you probably won’t find yourself using it directly.

Required Associated Types§

source

type Payload: Payload

The type of the payload contained.

Required Methods§

source

fn payload_mut(&mut self) -> &mut Self::Payload

Gain mutable access to the underlying payload.

source

fn payload_ref(&self) -> &Self::Payload

Gain immutable access to the underlying payload.

Provided Methods§

source

fn with_payload_mut<F>(self, f: F) -> Selfwhere Self: Sized, F: FnOnce(&mut Self::Payload),

Update payload with a function

Implementations on Foreign Types§

source§

impl<L, R> HasPayload for Either<L, R>where L: HasPayload, R: HasPayload<Payload = L::Payload>,

§

type Payload = <L as HasPayload>::Payload

source§

fn payload_mut(&mut self) -> &mut Self::Payload

source§

fn payload_ref(&self) -> &Self::Payload

Implementors§

source§

impl<P> HasPayload for JsonRequest<P>where P: Payload,

§

type Payload = P

source§

impl<P> HasPayload for MultipartRequest<P>where P: Payload,

§

type Payload = P

source§

impl<P> HasPayload for Pwhere P: Payload,

§

type Payload = P

source§

impl<R> HasPayload for TraceRequest<R>where R: HasPayload,

Available on crate feature trace_adaptor only.
source§

impl<R: HasPayload + Clone> HasPayload for ThrottlingRequest<R>

Available on crate feature throttle only.
source§

impl<R: Request> HasPayload for AutoRequest<R>

Available on crate feature auto_send only.
source§

impl<R: Request<Payload = GetMe>> HasPayload for CachedMeRequest<R>

Available on crate feature cache_me only.
source§

impl<T, E> HasPayload for ErasedRequest<'_, T, E>where T: Payload,

Available on crate feature erased only.
§

type Payload = T