Skip to main content

OcpiReply

Struct OcpiReply 

Source
pub struct OcpiReply<T> { /* private fields */ }
Available on crate feature server only.
Expand description

An OCPI response on its way out: the envelope, plus the headers that must accompany it.

Every OCPI response carries the request and correlation IDs it was called with:

Every request SHALL contain a unique request ID, the response to this request SHALL contain the same ID.

so this type carries them rather than leaving it to each handler to remember.

Implementations§

Source§

impl<T: Validate> OcpiReply<T>

Source

pub fn ok(data: T) -> Self

A 1000 Generic success reply with a payload, answered with HTTP 200.

The payload is validated on its way out, every violation is logged by JSON Pointer at warn, and it is sent anyway. Refusing a partner’s GET because one Location in a page of a hundred has a 46-character name turns this party’s data quality into an outage on theirs; serving it silently is how it becomes their support ticket weeks later.

A handler that would rather refuse calls validate itself and returns OcpiError::Invalid.

Source

pub fn created(data: T) -> Self

A 1000 reply for an object that was newly created, answered with HTTP 201.

HTTP 201 - Created when the object has been newly created in the server system.

Source§

impl<T> OcpiReply<T>

Source

pub fn no_content() -> Self

A 1000 reply with no payload, for a PUT or PATCH whose response body is unspecified.

We also advise that in such cases, platform sending the response leave the data field unset in the response format.

Source

pub fn with_ids(self, ids: RequestIds) -> Self

Attaches the request and correlation IDs of the request being answered.

Source

pub fn with_routing(self, routing: RoutingHeaders) -> Self

Attaches the routing headers of the response.

Pass the headers already swapped for the response direction; see RoutingHeaders::response_from.

Source

pub fn with_headers(self, headers: HeaderMap) -> Self

Adds arbitrary response headers, such as the pagination trio or a Location.

Source

pub const fn with_http_status(self, status: HttpStatus) -> Self

Overrides the HTTP status.

Source

pub fn with_message(self, message: impl Into<String>) -> Self

Sets the status_message.

Source

pub const fn envelope(&self) -> &OcpiResponse<T>

The envelope that will be sent.

Trait Implementations§

Source§

impl<T: Debug> Debug for OcpiReply<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T: Serialize> IntoResponse for OcpiReply<T>

Source§

fn into_response(self) -> Response

Create a response.

Auto Trait Implementations§

§

impl<T> Freeze for OcpiReply<T>
where OcpiResponse<T>: Freeze,

§

impl<T> RefUnwindSafe for OcpiReply<T>

§

impl<T> Send for OcpiReply<T>
where OcpiResponse<T>: Send,

§

impl<T> Sync for OcpiReply<T>
where OcpiResponse<T>: Sync,

§

impl<T> Unpin for OcpiReply<T>
where OcpiResponse<T>: Unpin,

§

impl<T> UnsafeUnpin for OcpiReply<T>

§

impl<T> UnwindSafe for OcpiReply<T>

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + 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
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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