Struct rocketjson_data::api::response::ApiResponse [−][src]
pub struct ApiResponse<T> {
pub json: Json<T>,
pub status: Status,
}
Expand description
Is returned by enpoints to achieve a Json Response
Requirements
T has to implement serde::Serialize
Example
- Code
#[derive(serde::Serialize)]
pub struct TestResponse {
data: String
}
#[post("/test")]
pub fn test() -> rocketjson::ApiResponse<TestResponse> {
rocketjson::ApiResponse::new(
rocket::http::Status::Ok,
TestResponse { data: String::from("test") }
)
}
- Response (200 OK)
{
data: "test"
}
Fields
json: Json<T>
This is the Json-data sent to the client
status: Status
This is the Statuscode sent to the client, it is not included in the Json
Implementations
Trait Implementations
Returns Ok
if a Response
could be generated successfully. Otherwise,
returns an Err
with a failing Status
. Read more
Auto Trait Implementations
impl<T> RefUnwindSafe for ApiResponse<T> where
T: RefUnwindSafe,
impl<T> Send for ApiResponse<T> where
T: Send,
impl<T> Sync for ApiResponse<T> where
T: Sync,
impl<T> Unpin for ApiResponse<T> where
T: Unpin,
impl<T> UnwindSafe for ApiResponse<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
pub fn into_collection<A>(self) -> SmallVec<A> where
A: Array<Item = T>,
Converts self
into a collection.
Convert self
to an expression for Diesel’s query builder. Read more
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
fn as_sql<'a, T>(&'a self) -> <&'a Self as AsExpression<T>>::Expression where
&'a Self: AsExpression<T>,
Convert &self
to an expression for Diesel’s query builder. Read more
pub fn vzip(self) -> V
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more