chore: switch to rocket_empty [skip ci]

This commit is contained in:
Paul Makles
2022-06-02 15:21:31 +01:00
parent bb70294546
commit 3e55ff3577
5 changed files with 20 additions and 36 deletions

12
Cargo.lock generated
View File

@@ -3022,6 +3022,7 @@ dependencies = [
"revolt-quark",
"rocket",
"rocket_cors",
"rocket_empty",
"rocket_okapi",
"schemars",
"serde",
@@ -3061,6 +3062,7 @@ dependencies = [
"regex",
"reqwest",
"rocket",
"rocket_empty",
"rocket_http",
"rocket_okapi",
"schemars",
@@ -3179,6 +3181,16 @@ dependencies = [
"url",
]
[[package]]
name = "rocket_empty"
version = "0.1.0"
source = "git+https://github.com/insertish/rocket_empty?branch=rc1#5b987e4d5090d28c6658aca25f09f7458e0de0fe"
dependencies = [
"okapi",
"rocket",
"rocket_okapi",
]
[[package]]
name = "rocket_http"
version = "0.5.0-rc.1"

View File

@@ -52,6 +52,7 @@ mobc = { version = "0.7.3" }
mobc-redis = { version = "0.7.0", default-features = false, features = ["async-std-comp"] }
# web
rocket_empty = { git = "https://github.com/insertish/rocket_empty", branch = "rc1" }
rocket = { version = "0.5.0-rc.1", default-features = false, features = ["json"] }
mongodb = { version = "1.2.2", features = ["async-std-runtime"], default-features = false }
rocket_cors = { git = "https://github.com/lawliet89/rocket_cors", rev = "5843861a88958c16bfaa0b40f0d8910772bcd2f6" }

View File

@@ -8,7 +8,7 @@ edition = "2021"
[features]
mongo = [ "mongodb" ]
rocket_impl = [ "rocket" ]
rocket_impl = [ "rocket", "rocket_empty" ]
test = [ "async-std", "mongo", "mongodb/async-std-runtime", "rocket_impl", "rauth" ]
default = [ "test" ]
@@ -66,6 +66,7 @@ web-push = "0.7.2"
rauth = { optional = true, git = "https://github.com/insertish/rauth", rev = "001a9698c56cea79e69e4ae71d7bc2cb48aec1a6" }
rocket = { optional = true, version = "=0.5.0-rc.1", default-features = false, features = ["json"] }
rocket_http = { optional = true, version = "=0.5.0-rc.1" }
rocket_empty = { optional = true, git = "https://github.com/insertish/rocket_empty", branch = "rc1" }
# Sentry
sentry = "0.25.0"

View File

@@ -39,9 +39,12 @@ pub use permissions::defn::*;
pub use permissions::{get_relationship, perms};
pub use util::r#ref::Ref;
pub use util::result::{EmptyResponse, Error, Result};
pub use util::result::{Error, Result};
pub use util::variables;
#[cfg(feature = "rocket_impl")]
pub use rocket_empty::EmptyResponse;
#[cfg(feature = "rocket_impl")]
use rocket::State;

View File

@@ -1,4 +1,4 @@
use okapi::openapi3::{self, RefOr, SchemaObject};
use okapi::openapi3::{self, SchemaObject};
use rocket::{
http::{ContentType, Status},
response::{self, Responder},
@@ -116,21 +116,9 @@ impl Error {
}
}
/// Empty 204 HTTP Response
pub struct EmptyResponse;
/// Result type with custom Error
pub type Result<T, E = Error> = std::result::Result<T, E>;
// ! FIXME: #[cfg]
impl<'r> Responder<'r, 'static> for EmptyResponse {
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
Response::build()
.status(rocket::http::Status { code: 204 })
.ok()
}
}
/// HTTP response builder for Error enum
impl<'r> Responder<'r, 'static> for Error {
fn respond_to(self, _: &'r Request<'_>) -> response::Result<'static> {
@@ -241,24 +229,3 @@ impl rocket_okapi::response::OpenApiResponderInner for Error {
})
}
}
impl rocket_okapi::response::OpenApiResponderInner for EmptyResponse {
fn responses(
_gen: &mut rocket_okapi::gen::OpenApiGenerator,
) -> std::result::Result<openapi3::Responses, rocket_okapi::OpenApiError> {
let mut responses = okapi::Map::new();
responses.insert(
"204".to_string(),
RefOr::Object(openapi3::Response {
description: "Success".to_string(),
..Default::default()
}),
);
Ok(openapi3::Responses {
responses,
..Default::default()
})
}
}