pub trait JsonResource {
type Model;
// Required method
fn to_json(model: &Self::Model) -> Json;
// Provided methods
fn wrap() -> Option<&'static str> { ... }
fn make(model: &Self::Model) -> ResourceResponse { ... }
fn collection<'a, I>(models: I) -> ResourceResponse
where I: IntoIterator<Item = &'a Self::Model>,
Self::Model: 'a { ... }
}Expand description
How a model becomes JSON. Implement it once per type that leaves the server.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn wrap() -> Option<&'static str>
fn wrap() -> Option<&'static str>
The key the data sits under. Some("data") by default, as in Laravel;
None sends the object or array bare.
fn make(model: &Self::Model) -> ResourceResponse
fn collection<'a, I>(models: I) -> ResourceResponse
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".