mirror of
https://github.com/rwf2/Rocket.git
synced 2025-02-02 14:52:10 +00:00
02011a1307
This commit is a codebase-wide cleanup driven by clippy warnings. In addition to fixing every reasonable warning, the following new functionality was introduced: * `Accept::new()` now takes any `T: Into<QMediaType>` iterator. * `TempFile::is_empty()` was added. * `HeaderMap` now implements `IntoIterator`. This commit makes the following breaking changes: * The `IntoCollection` trait is gone. Generics previously bound by the trait are now bound by `IntoIterator`. This affects: - `Accept::new()` - `ContentType::with_params()` - `Permission::{allow, allowed}()` * `MediaType`, `QMediaType`, and `Allow` implement `IntoIterator`, enabling most existing code to continue working without change. * The inherent `HeaderMap::into_iter()` method was removed. * The `Ok` variant in ErrorKind::Liftoff` is now `Box<Rocket<Orbit>>`.
30 lines
805 B
Rust
30 lines
805 B
Rust
#![allow(dead_code)] // This test is only here so that we can ensure it compiles.
|
|
|
|
#[macro_use] extern crate rocket;
|
|
|
|
use rocket::{Request, State};
|
|
use rocket::response::{Responder, Result};
|
|
|
|
struct SomeState;
|
|
|
|
pub struct CustomResponder<'r, R> {
|
|
responder: R,
|
|
state: &'r SomeState,
|
|
}
|
|
|
|
impl<'r, 'o: 'r, R: Responder<'r, 'o>> Responder<'r, 'o> for CustomResponder<'r, R> {
|
|
fn respond_to(self, req: &'r Request<'_>) -> Result<'o> {
|
|
self.responder.respond_to(req)
|
|
}
|
|
}
|
|
|
|
#[get("/unit_state")]
|
|
fn unit_state(state: &State<SomeState>) -> CustomResponder<'_, ()> {
|
|
CustomResponder { responder: (), state: &*state }
|
|
}
|
|
|
|
#[get("/string_state")]
|
|
fn string_state(state: &State<SomeState>) -> CustomResponder<'_, String> {
|
|
CustomResponder { responder: "".to_string(), state: &*state }
|
|
}
|