Skip to main content

ApiResponseBuilder

Struct ApiResponseBuilder 

Source
pub struct ApiResponseBuilder<T> { /* private fields */ }
Expand description

Builder for ApiResponse.

Obtain one via ApiResponse::builder.

§Design note — simple builder, not typestate

HealthCheckBuilder and ReadinessResponseBuilder use a typestate pattern because they have multiple required fields that must all be provided before the type is valid to construct. ApiResponseBuilder is different: the only required field is data, which is supplied at construction time via ApiResponse::builder. Everything else (meta, links) is optional and has a sensible default, so there are no remaining required fields for the typestate machinery to enforce. A plain builder is therefore appropriate here.

Implementations§

Source§

impl<T> ApiResponseBuilder<T>

Source

pub fn meta(self, meta: ResponseMeta) -> Self

Set the meta field.

§Examples
use api_bones::response::{ApiResponse, ResponseMeta};

let response: ApiResponse<&str> = ApiResponse::builder("hi")
    .meta(ResponseMeta::new().request_id("req-1"))
    .build();
assert_eq!(response.meta.request_id.as_deref(), Some("req-1"));

Set the links field.

§Examples
use api_bones::response::ApiResponse;
use api_bones::links::{Link, Links};

let response: ApiResponse<&str> = ApiResponse::builder("hi")
    .links(Links::new().push(Link::self_link("/items/1")))
    .build();
assert!(response.links.is_some());
Source

pub fn build(self) -> ApiResponse<T>

Consume the builder and produce an ApiResponse.

§Examples
use api_bones::response::ApiResponse;

let response: ApiResponse<i32> = ApiResponse::builder(42).build();
assert_eq!(response.data, 42);
assert!(response.links.is_none());

Auto Trait Implementations§

§

impl<T> Freeze for ApiResponseBuilder<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ApiResponseBuilder<T>
where T: RefUnwindSafe,

§

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

§

impl<T> Sync for ApiResponseBuilder<T>
where T: Sync,

§

impl<T> Unpin for ApiResponseBuilder<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ApiResponseBuilder<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for ApiResponseBuilder<T>
where T: UnwindSafe,

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