Created
July 14, 2017 14:31
-
-
Save lawliet89/988d8367aaf4988f1263fb5d9ea6df5b to your computer and use it in GitHub Desktop.
Rocket lifetime cargo expand
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![feature(prelude_import)] | |
#![no_std] | |
#![feature(plugin, custom_derive)] | |
#![plugin(rocket_codegen)] | |
#[prelude_import] | |
use std::prelude::v1::*; | |
#[macro_use] | |
extern crate std as std; | |
extern crate rocket; | |
use std::marker::PhantomData; | |
use rocket::State; | |
use rocket::response; | |
struct SomeState {} | |
pub struct Responder<'r, R> { | |
responder: R, | |
state: &'r SomeState, | |
marker: PhantomData<response::Responder<'r>>, | |
} | |
impl<'r, R: response::Responder<'r>> Responder<'r, R> { | |
fn new(responder: R, state: &'r SomeState) -> Self { | |
Self { | |
responder, | |
state, | |
marker: PhantomData, | |
} | |
} | |
} | |
impl<'r, R: response::Responder<'r>> response::Responder<'r> for Responder<'r, R> { | |
fn respond_to( | |
self, | |
request: &rocket::Request, | |
) -> Result<response::Response<'r>, rocket::http::Status> { | |
self.responder.respond_to(request) | |
} | |
} | |
#[allow(unreachable_code)] | |
fn rocket_route_fn_string_state<'_b>( | |
__req: &'_b ::rocket::Request, | |
__data: ::rocket::Data, | |
) -> ::rocket::handler::Outcome<'_b> { | |
#[allow(non_snake_case)] | |
let rocket_param_state: State<SomeState> = | |
match ::rocket::request::FromRequest::from_request(__req) { | |
::rocket::Outcome::Success(v) => v, | |
::rocket::Outcome::Forward(_) => return ::rocket::Outcome::Forward(__data), | |
::rocket::Outcome::Failure((code, _)) => return ::rocket::Outcome::Failure(code), | |
}; | |
let responder = string_state(rocket_param_state); | |
::rocket::handler::Outcome::from(__req, responder) | |
} | |
/// Rocket code generated static route information structure. | |
#[allow(non_upper_case_globals)] | |
#[rocket_route_info] | |
pub static static_rocket_route_info_for_string_state: ::rocket::StaticRouteInfo = | |
::rocket::StaticRouteInfo { | |
method: ::rocket::http::Method::Get, | |
path: "/string_state", | |
handler: rocket_route_fn_string_state, | |
format: None, | |
rank: None, | |
}; | |
#[rocket_route(static_rocket_route_info_for_string_state)] | |
fn string_state(state: State<SomeState>) -> Responder<String> { | |
Responder::new("Testing".to_string(), state.inner()) | |
} | |
#[allow(unreachable_code)] | |
fn rocket_route_fn_string<'_b>( | |
__req: &'_b ::rocket::Request, | |
__data: ::rocket::Data, | |
) -> ::rocket::handler::Outcome<'_b> { | |
let responder = string(); | |
::rocket::handler::Outcome::from(__req, responder) | |
} | |
/// Rocket code generated static route information structure. | |
#[allow(non_upper_case_globals)] | |
#[rocket_route_info] | |
pub static static_rocket_route_info_for_string: ::rocket::StaticRouteInfo = | |
::rocket::StaticRouteInfo { | |
method: ::rocket::http::Method::Get, | |
path: "/string", | |
handler: rocket_route_fn_string, | |
format: None, | |
rank: None, | |
}; | |
#[rocket_route(static_rocket_route_info_for_string)] | |
fn string() -> String { | |
"Testing".to_string() | |
} | |
#[allow(unreachable_code)] | |
fn rocket_route_fn_str_route<'_b>( | |
__req: &'_b ::rocket::Request, | |
__data: ::rocket::Data, | |
) -> ::rocket::handler::Outcome<'_b> { | |
#[allow(non_snake_case)] | |
let rocket_param_state: State<SomeState> = | |
match ::rocket::request::FromRequest::from_request(__req) { | |
::rocket::Outcome::Success(v) => v, | |
::rocket::Outcome::Forward(_) => return ::rocket::Outcome::Forward(__data), | |
::rocket::Outcome::Failure((code, _)) => return ::rocket::Outcome::Failure(code), | |
}; | |
let responder = str_route(rocket_param_state); | |
::rocket::handler::Outcome::from(__req, responder) | |
} | |
/// Rocket code generated static route information structure. | |
#[allow(non_upper_case_globals)] | |
#[rocket_route_info] | |
pub static static_rocket_route_info_for_str_route: ::rocket::StaticRouteInfo = | |
::rocket::StaticRouteInfo { | |
method: ::rocket::http::Method::Get, | |
path: "/str_route", | |
handler: rocket_route_fn_str_route, | |
format: None, | |
rank: None, | |
}; | |
#[rocket_route(static_rocket_route_info_for_str_route)] | |
fn str_route(state: State<SomeState>) -> Responder<&str> { | |
Responder::new("Testing", state.inner()) | |
} | |
#[allow(unreachable_code)] | |
fn rocket_route_fn_unit_state<'_b>( | |
__req: &'_b ::rocket::Request, | |
__data: ::rocket::Data, | |
) -> ::rocket::handler::Outcome<'_b> { | |
#[allow(non_snake_case)] | |
let rocket_param_state: State<SomeState> = | |
match ::rocket::request::FromRequest::from_request(__req) { | |
::rocket::Outcome::Success(v) => v, | |
::rocket::Outcome::Forward(_) => return ::rocket::Outcome::Forward(__data), | |
::rocket::Outcome::Failure((code, _)) => return ::rocket::Outcome::Failure(code), | |
}; | |
let responder = unit_state(rocket_param_state); | |
::rocket::handler::Outcome::from(__req, responder) | |
} | |
/// Rocket code generated static route information structure. | |
#[allow(non_upper_case_globals)] | |
#[rocket_route_info] | |
pub static static_rocket_route_info_for_unit_state: ::rocket::StaticRouteInfo = | |
::rocket::StaticRouteInfo { | |
method: ::rocket::http::Method::Get, | |
path: "/unit_state", | |
handler: rocket_route_fn_unit_state, | |
format: None, | |
rank: None, | |
}; | |
#[rocket_route(static_rocket_route_info_for_unit_state)] | |
fn unit_state(state: State<SomeState>) -> Responder<()> { | |
Responder::new((), state.inner()) | |
} | |
#[allow(unreachable_code)] | |
fn rocket_route_fn_unit<'_b>( | |
__req: &'_b ::rocket::Request, | |
__data: ::rocket::Data, | |
) -> ::rocket::handler::Outcome<'_b> { | |
let responder = unit(); | |
::rocket::handler::Outcome::from(__req, responder) | |
} | |
/// Rocket code generated static route information structure. | |
#[allow(non_upper_case_globals)] | |
#[rocket_route_info] | |
pub static static_rocket_route_info_for_unit: ::rocket::StaticRouteInfo = | |
::rocket::StaticRouteInfo { | |
method: ::rocket::http::Method::Get, | |
path: "/unit", | |
handler: rocket_route_fn_unit, | |
format: None, | |
rank: None, | |
}; | |
#[rocket_route(static_rocket_route_info_for_unit)] | |
fn unit() -> () { | |
() | |
} | |
#[allow(dead_code)] | |
fn main() { | |
rocket::Rocket::ignite() | |
.manage(SomeState {}) | |
.mount( | |
"/", | |
<[_]>::into_vec( | |
box [ | |
::rocket::Route::from(&static_rocket_route_info_for_string_state), | |
::rocket::Route::from(&static_rocket_route_info_for_string), | |
::rocket::Route::from(&static_rocket_route_info_for_str_route), | |
::rocket::Route::from(&static_rocket_route_info_for_string), | |
::rocket::Route::from(&static_rocket_route_info_for_unit_state), | |
::rocket::Route::from(&static_rocket_route_info_for_unit), | |
], | |
), | |
) | |
.launch(); | |
} | |
pub mod __test { | |
extern crate test; | |
#[main] | |
pub fn main() -> () { | |
test::test_main_static(TESTS) | |
} | |
const TESTS: &'static [self::test::TestDescAndFn] = &[]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment