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