use jerrycan::prelude::*;
#[jerrycan::main]
async fn demo_main() -> Result<()> {
let _app = App::new().route("/ping", get(|| async { "pong" }));
Ok(())
}
#[test]
fn facade_paths_compile() {
let _ = demo_main as fn() -> Result<()>;
}
#[derive(Debug)]
struct LeadId(i64);
impl std::str::FromStr for LeadId {
type Err = std::num::ParseIntError;
fn from_str(s: &str) -> std::result::Result<Self, Self::Err> {
Ok(LeadId(s.parse()?))
}
}
jerrycan::path_param!(LeadId);
#[tokio::test]
async fn path_param_macro_resolves_through_the_facade() {
async fn show(Path(id): Path<LeadId>) -> Result<Json<i64>> {
Ok(Json(id.0))
}
let t = App::new()
.mount(
"/ws/{ws}",
Module::new("leads").route("/leads/{id}", get(show)),
)
.into_test();
assert_eq!(t.get("/ws/7/leads/42").await.json::<i64>(), 42);
}