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 as HasPayload>::Payload>,

§

type Payload = <L as HasPayload>::Payload

source§

fn payload_mut(&mut self) -> &mut <Either<L, R> as HasPayload>::Payload

source§

fn payload_ref(&self) -> &<Either<L, R> as HasPayload>::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 AutoRequest<R>where R: Request,

source§

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

source§

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

source§

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

source§

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

§

type Payload = T