[![Rust](https://github.com/kolbma/rocket-response/actions/workflows/rust.yml/badge.svg)](https://github.com/kolbma/rocket-response/actions/workflows/rust.yml) [![crates.io](https://img.shields.io/crates/v/rocket-response)](https://crates.io/crates/rocket-response) [![docs](https://docs.rs/rocket-response/badge.svg)](https://docs.rs/rocket-response) # rocket-response - Provides enum for variable Rocket Responses This [crate] provides 3 enums to be flexible in returning [Responses]. 1. [RocketResponse] provides all non-generic [Response] types. 2. [RocketResponseGeneric] provides [Response]-types non-generic and generic using a single generic type. 3. [RocketResponseGeneric2] allows a different [Flash] type. If you miss any [Response], you are welcome to open an [issue] or even better provide a pull-request! Because it is difficult to decide on the generics what might be useful, your usecases are really welcome in an [issue]. ## Usage For usage add the crate to your dependencies ```toml [dependencies] rocket-response = { version = "0.0.1-rc.2" } ``` ## Features You can depend on a couple of features, which provide additional types. * json * msgpack * templates-handlebars or templates-tera ```toml [dependencies] rocket-response = { version = "0.0.1-rc.2", features = ["json", "templates-tera"] } ``` ## Example ```rust use rocket::{get, response::{self, status, Redirect}}; use rocket_response::RocketResponseGeneric2 as RocketResponse; #[get("/")] pub(crate) fn rocket_response_generic2( id: usize, ) -> RocketResponse<&'static str, Redirect> { match id { 0 => RocketResponse::Flash(response::Flash::error( Redirect::to("/"), format!("Invalid id {}", id), )), 1 => RocketResponse::Unauthorized(status::Unauthorized(Some( "admin need authentication", ))), _ => RocketResponse::Html(response::content::Html( "Hello world