~lthms/typed-urls

bb0b25803aea783924d68628c7b24130dcab34da — Thomas Letan 2 months ago 1f203c3 main
Turn typed-urls-tera into a feature and introduce the actix feature
5 files changed, 34 insertions(+), 13 deletions(-)

M Cargo.toml
A src/actix.rs
M src/lib.rs
R typed-urls-tera/src/lib.rs => src/tera.rs
D typed-urls-tera/Cargo.toml
M Cargo.toml => Cargo.toml +9 -2
@@ 1,5 1,5 @@
[workspace]
members = ['typed-urls-derive', 'typed-urls-tera']
members = ['typed-urls-derive']

[package]
name = "typed-urls"


@@ 11,4 11,11 @@ license = "AGPL-3.0-or-later"
[dependencies]
serde = "1.0"
serde_json = "1.0"
typed-urls-derive = { path = "typed-urls-derive/" }
\ No newline at end of file
typed-urls-derive = { path = "typed-urls-derive/" }
tera = { version = "1.5", optional = true }
actix-web = { version = "3.0", optional = true }

[features]
default = []
tera-templates = ["tera"]
actix-routes = ["actix-web"]
\ No newline at end of file

A src/actix.rs => src/actix.rs +19 -0
@@ 0,0 1,19 @@
use std::fmt::Display;

use actix_web::Resource;
use actix_web::web::resource;

use crate::TypedUrl;

pub trait Endpoint : TypedUrl {
    fn endpoint(route : Self::Route) -> Resource;
}

impl<U> Endpoint for U
where
    U : TypedUrl + Display
{
    fn endpoint(r : U::Route) -> Resource {
        resource(r.to_string())
    }
}

M src/lib.rs => src/lib.rs +5 -0
@@ 4,6 4,11 @@ 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;


R typed-urls-tera/src/lib.rs => src/tera.rs +1 -1
@@ 3,7 3,7 @@ use std::fmt::{Debug, Display};

use serde_json::Value;
use tera::{Error, Function, Tera};
use typed_urls::TypedUrl;
use crate::TypedUrl;

struct TeraFunction<U>(U::Route)
where

D typed-urls-tera/Cargo.toml => typed-urls-tera/Cargo.toml +0 -10
@@ 1,10 0,0 @@
[package]
name = "typed-urls-tera"
version = "0.1.0"
authors = ["Thomas Letan <lthms@soap.coffee>"]
edition = "2018"

[dependencies]
tera = "*"
serde_json = "*"
typed-urls = { path = "../" }
\ No newline at end of file