Compare commits
8 commits
Author | SHA1 | Date | |
---|---|---|---|
51508c818a | |||
322179ea13 | |||
5134624b06 | |||
2b24a6def1 | |||
0158d7d7e0 | |||
560aa3d2af | |||
09a73d3ee5 | |||
11b201004a |
11 changed files with 53 additions and 33 deletions
4
Cargo.lock
generated
4
Cargo.lock
generated
|
@ -101,7 +101,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "axum-controller"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"axum-controller-macros",
|
||||
|
@ -114,7 +114,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "axum-controller-macros"
|
||||
version = "0.2.0"
|
||||
version = "0.2.2"
|
||||
dependencies = [
|
||||
"axum",
|
||||
"prettyplease",
|
||||
|
|
|
@ -6,10 +6,10 @@ resolver = "3"
|
|||
authors = ["Tristan Druyen <ek36g2vcc@mozmail.com>"]
|
||||
categories = ["web-programming"]
|
||||
description = "Helper macro's for better readability of axum handlers"
|
||||
edition = "2024"
|
||||
edition = "2021"
|
||||
homepage = "https://git.vlt81.de/vault81/axum-controller"
|
||||
keywords = ["axum", "controller", "macro", "routing"]
|
||||
license = "AGPL-3.0-or-later"
|
||||
readme = "README.md"
|
||||
repository = "https://git.vlt81.de/vault81/axum-controller"
|
||||
version = "0.2.0"
|
||||
version = "0.3.0"
|
||||
|
|
|
@ -1,5 +1,11 @@
|
|||
[](https://crates.io/crates/axum-controller)
|
||||
[](https://docs.rs/axum-controller)
|
||||

|
||||
|
||||
# DEPRECATED
|
||||
|
||||
This crate does not receive further development, it *might* work for your use case.
|
||||
I've changed how I do routing & recommend checking out [axum-folder-router](https://crates.io/crates/axum-folder-router).
|
||||
|
||||
# Axum-Controller
|
||||
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
cargo-features = ["edition2024"]
|
||||
[package]
|
||||
authors.workspace = true
|
||||
categories.workspace = true
|
||||
|
@ -16,7 +15,7 @@ version.workspace = true
|
|||
prettyplease = "0.2"
|
||||
proc-macro2 = "1"
|
||||
quote = "1"
|
||||
syn = { version = "2", features = ["parsing"] }
|
||||
syn = { version = "2", features = ["extra-traits", "parsing", "printing"] }
|
||||
|
||||
[dev-dependencies]
|
||||
axum = { version = "0.8", features = [] }
|
||||
|
|
|
@ -2,9 +2,9 @@
|
|||
use proc_macro::TokenStream;
|
||||
use proc_macro2::Ident;
|
||||
use syn::{
|
||||
ItemImpl, MetaNameValue,
|
||||
parse::{Parse, ParseStream},
|
||||
punctuated::Punctuated,
|
||||
ItemImpl, MetaNameValue,
|
||||
};
|
||||
#[macro_use]
|
||||
extern crate quote;
|
||||
|
@ -131,6 +131,7 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
.map(move |route| {
|
||||
quote! {
|
||||
.typed_route(#struct_name :: #route)
|
||||
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
@ -139,6 +140,23 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
.nest(#route, __nested_router)
|
||||
};
|
||||
|
||||
let nested_router_qoute = quote! {
|
||||
axum::Router::new()
|
||||
#nesting_call
|
||||
};
|
||||
let unnested_router_quote = quote! {
|
||||
__nested_router
|
||||
};
|
||||
let maybe_nesting_call = if let syn::Expr::Lit(lit) = route {
|
||||
if lit.eq(&syn::parse_quote!("/")) {
|
||||
unnested_router_quote
|
||||
} else {
|
||||
nested_router_qoute
|
||||
}
|
||||
} else {
|
||||
nested_router_qoute
|
||||
};
|
||||
|
||||
let middleware_calls = args
|
||||
.middlewares
|
||||
.clone()
|
||||
|
@ -151,15 +169,14 @@ pub fn controller(attr: TokenStream, item: TokenStream) -> TokenStream {
|
|||
// one where it's #state
|
||||
let from_controller_into_router_impl = quote! {
|
||||
impl #struct_name {
|
||||
fn into_router(state: #state) -> axum::Router<#state> {
|
||||
pub fn into_router(state: #state) -> axum::Router<#state> {
|
||||
let __nested_router = axum::Router::new()
|
||||
#(#route_calls)*
|
||||
#(#middleware_calls)*
|
||||
.with_state(state)
|
||||
;
|
||||
|
||||
axum::Router::new()
|
||||
#nesting_call
|
||||
#maybe_nesting_call
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
cargo-features = ["edition2024"]
|
||||
|
||||
[package]
|
||||
authors.workspace = true
|
||||
categories.workspace = true
|
||||
|
@ -14,11 +12,12 @@ repository.workspace = true
|
|||
version.workspace = true
|
||||
|
||||
[dependencies]
|
||||
axum-controller-macros = { path = "../axum-controller-macros", version = "0.2.0" }
|
||||
axum-typed-routing = { path = "../vendor/axum-typed-routing", version = "0.2.0" }
|
||||
axum-controller-macros = { path = "../axum-controller-macros", version = "0.3" }
|
||||
axum-typed-routing = { path = "../vendor/axum-typed-routing", version = "0.2.0"}
|
||||
|
||||
[dev-dependencies]
|
||||
axum = "0.8"
|
||||
axum-typed-routing = { path = "../vendor/axum-typed-routing", version = "0.2", features = []}
|
||||
axum-test = { version = "17", features = [] }
|
||||
json = "0.12"
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
|
|
|
@ -15,5 +15,5 @@
|
|||
//! ```
|
||||
|
||||
pub use axum_controller_macros::controller;
|
||||
pub use axum_typed_routing::TypedRouter;
|
||||
pub use axum_typed_routing::route;
|
||||
pub use axum_typed_routing::TypedRouter;
|
||||
|
|
|
@ -90,17 +90,17 @@
|
|||
'';
|
||||
};
|
||||
packages = {
|
||||
default = pkgs.callPackage ./package.nix { };
|
||||
# default = pkgs.callPackage ./package.nix { };
|
||||
};
|
||||
}) // {
|
||||
hydraJobs =
|
||||
let
|
||||
system = "x86_64-linux";
|
||||
packages = self.packages."${system}";
|
||||
# packages = self.packages."${system}";
|
||||
devShells = self.devShells."${system}";
|
||||
in
|
||||
{
|
||||
inherit packages devShells;
|
||||
inherit devShells;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
1
vendor/axum-typed-routing-macros/src/lib.rs
vendored
1
vendor/axum-typed-routing-macros/src/lib.rs
vendored
|
@ -97,6 +97,7 @@ pub fn route(attr: TokenStream, mut item: TokenStream) -> TokenStream {
|
|||
/// - `security` is the OpenApi security requirements.
|
||||
/// - `responses` are the OpenApi responses.
|
||||
/// - `transform` is a closure that takes an `TransformOperation` and returns an `TransformOperation`.
|
||||
///
|
||||
/// This may override the other options. (see the crate `aide` for more information).
|
||||
///
|
||||
/// # Example
|
||||
|
|
4
vendor/axum-typed-routing/examples/basic.rs
vendored
4
vendor/axum-typed-routing/examples/basic.rs
vendored
|
@ -1,6 +1,6 @@
|
|||
#![allow(unused)]
|
||||
use axum::extract::{State, Json};
|
||||
use axum_typed_routing::{TypedRouter, route};
|
||||
use axum::extract::{Json, State};
|
||||
use axum_typed_routing::{route, TypedRouter};
|
||||
|
||||
#[route(GET "/item/:id?amount&offset")]
|
||||
async fn item_handler(
|
||||
|
|
2
vendor/axum-typed-routing/tests/main.rs
vendored
2
vendor/axum-typed-routing/tests/main.rs
vendored
|
@ -113,7 +113,6 @@ async fn test_wildcard() {
|
|||
assert_eq!(response.json::<String>(), "foo/bar");
|
||||
}
|
||||
|
||||
|
||||
#[cfg(feature = "aide")]
|
||||
mod aide_support {
|
||||
use super::*;
|
||||
|
@ -231,4 +230,3 @@ mod aide_support {
|
|||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue