1use std::collections::HashMap;
6use std::fmt::Display;
7
8use serde_json::Value;
9
10#[cfg(feature = "actix-routes")]
11pub mod actix;
12#[cfg(feature = "tera-templates")]
13pub mod tera;
14
15pub trait TypedUrl: Sized {
16 type Route: Display;
17
18 fn routes() -> &'static [Self::Route];
19
20 fn from_route(
21 route : &Self::Route,
22 args : &HashMap<String, Value>,
23 ) -> Option<Self>;
24}
25
26pub trait UrlPathParam {
27 fn from_value(value : &Value) -> Option<Self>
28 where
29 Self : std::marker::Sized;
30}
31
32impl UrlPathParam for String {
33 fn from_value(value : &Value) -> Option<Self> {
34 value.as_str().map(|x| x.to_owned())
35 }
36}
37
38impl UrlPathParam for i32 {
39 fn from_value(value : &Value) -> Option<Self> {
40 value.as_i64().map(|x| x as i32)
41 }
42}