pub struct JsonApiCollection<T: Serialize + Send + Sync + 'static, R: JsonApiResource<T>> { /* private fields */ }Expand description
A collection-resource JSON:API document builder.
ⓘ
let doc = PostResource::collection(posts)
.with_query(&query)
.include("author", AuthorResource::make(author))
.with_links(json!({ "self": "/api/posts" }))
.to_array();Implementations§
Source§impl<T: Serialize + Send + Sync + 'static, R: JsonApiResource<T>> JsonApiCollection<T, R>
impl<T: Serialize + Send + Sync + 'static, R: JsonApiResource<T>> JsonApiCollection<T, R>
Sourcepub fn with_query(self, query: &JsonApiQuery) -> Self
pub fn with_query(self, query: &JsonApiQuery) -> Self
Apply the parsed query string context (sparse fieldsets, includes).
Sourcepub fn ignore_query_string(self) -> Self
pub fn ignore_query_string(self) -> Self
Ignore the query string — return full attributes and no includes.
Sourcepub fn include<T2: Serialize + Send + Sync + 'static, R2: JsonApiResource<T2> + Send + Sync + 'static>(
self,
path: &str,
child: JsonApiItem<T2, R2>,
) -> Self
pub fn include<T2: Serialize + Send + Sync + 'static, R2: JsonApiResource<T2> + Send + Sync + 'static>( self, path: &str, child: JsonApiItem<T2, R2>, ) -> Self
Register a related single resource for the top-level included array.
Sourcepub fn include_collection<T2: Serialize + Send + Sync + 'static, R2: JsonApiResource<T2> + Send + Sync + 'static>(
self,
path: &str,
child: JsonApiCollection<T2, R2>,
) -> Self
pub fn include_collection<T2: Serialize + Send + Sync + 'static, R2: JsonApiResource<T2> + Send + Sync + 'static>( self, path: &str, child: JsonApiCollection<T2, R2>, ) -> Self
Register a related collection for the top-level included array.
Sourcepub fn with_links(self, links: Value) -> Self
pub fn with_links(self, links: Value) -> Self
Set the top-level links object (e.g. pagination links).
Sourcepub fn with_meta(self, meta: Value) -> Self
pub fn with_meta(self, meta: Value) -> Self
Set additional top-level meta (merged with the automatic count).
Sourcepub fn resource_objects(&self, query: &JsonApiQuery) -> Vec<Value>
pub fn resource_objects(&self, query: &JsonApiQuery) -> Vec<Value>
The resource objects for every model in the collection.
Sourcepub fn to_array(&self) -> Value
pub fn to_array(&self) -> Value
Render the full document: { "data": [...], "meta": { "count": N }, "links": {...}, "included": [...] }.
Sourcepub fn to_json(&self) -> Result<String, Error>
pub fn to_json(&self) -> Result<String, Error>
Render the document as a pretty-printed JSON string.
Sourcepub fn into_inner(self) -> Vec<T>
pub fn into_inner(self) -> Vec<T>
Consume the builder and return the inner models.
Trait Implementations§
Source§impl<T: Serialize + Send + Sync + 'static, R: JsonApiResource<T>> IntoResponse for JsonApiCollection<T, R>
impl<T: Serialize + Send + Sync + 'static, R: JsonApiResource<T>> IntoResponse for JsonApiCollection<T, R>
Source§fn into_response(self) -> AxumResponse<Body>
fn into_response(self) -> AxumResponse<Body>
Create a response.
Auto Trait Implementations§
impl<T, R> !RefUnwindSafe for JsonApiCollection<T, R>
impl<T, R> !UnwindSafe for JsonApiCollection<T, R>
impl<T, R> Freeze for JsonApiCollection<T, R>
impl<T, R> Send for JsonApiCollection<T, R>
impl<T, R> Sync for JsonApiCollection<T, R>
impl<T, R> Unpin for JsonApiCollection<T, R>
impl<T, R> UnsafeUnpin for JsonApiCollection<T, R>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more