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>
impl<T> ApiResponseBuilder<T>
Sourcepub fn meta(self, meta: ResponseMeta) -> Self
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"));Sourcepub fn links(self, links: Links) -> Self
pub fn links(self, links: Links) -> Self
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());Sourcepub fn build(self) -> ApiResponse<T>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more