1
0
Fork 0
mirror of https://gitlab.com/msrd0/gotham-restful.git synced 2025-04-20 06:54:46 +00:00

implement no-content response

This commit is contained in:
Dominic 2019-10-05 14:50:05 +02:00
parent c8298b7bfa
commit 5a62af6319
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
4 changed files with 64 additions and 18 deletions

View file

@ -1,6 +1,6 @@
use crate::{ResourceType, StatusCode};
#[cfg(feature = "openapi")]
use crate::OpenapiSchema;
use crate::{OpenapiSchema, OpenapiType};
use serde::Serialize;
use serde_json::error::Error as SerdeJsonError;
use std::error::Error;
@ -12,6 +12,12 @@ pub trait ResourceResult
#[cfg(feature = "openapi")]
fn to_schema() -> OpenapiSchema;
#[cfg(feature = "openapi")]
fn default_status() -> StatusCode
{
StatusCode::OK
}
}
#[cfg(feature = "openapi")]
@ -86,3 +92,34 @@ impl<T : ResourceType> ResourceResult for Success<T>
T::to_schema()
}
}
/// This can be returned from a resource when there is no content to send.
pub struct NoContent;
impl From<()> for NoContent
{
fn from(_ : ()) -> Self
{
Self {}
}
}
impl ResourceResult for NoContent
{
fn to_json(&self) -> Result<(StatusCode, String), SerdeJsonError>
{
Ok((StatusCode::NO_CONTENT, "".to_string()))
}
#[cfg(feature = "openapi")]
fn to_schema() -> OpenapiSchema
{
<()>::to_schema()
}
#[cfg(feature = "openapi")]
fn default_status() -> StatusCode
{
StatusCode::NO_CONTENT
}
}