Compare commits
3 commits
Author | SHA1 | Date | |
---|---|---|---|
49df03b2e8 | |||
b7dd6f9379 | |||
c7d4ba974b |
6 changed files with 38 additions and 29 deletions
|
@ -6,6 +6,14 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
- Nothing yet
|
||||
|
||||
## [0.3.6] - 2025-04-17
|
||||
|
||||
- Better error messages when having route.rs files with invalid code
|
||||
|
||||
## [0.3.5] - 2025-04-16
|
||||
|
||||
- Moved macrotest to dev deps
|
||||
|
||||
## [0.3.4] - 2025-04-16
|
||||
|
||||
- Refactored huge lib.rs into 3 seperate files.
|
||||
|
|
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -94,7 +94,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "axum-folder-router"
|
||||
version = "0.3.4"
|
||||
version = "0.3.6"
|
||||
dependencies = [
|
||||
"anyhow",
|
||||
"axum",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "axum-folder-router"
|
||||
version = "0.3.4"
|
||||
version = "0.3.6"
|
||||
edition = "2021"
|
||||
readme = "./README.md"
|
||||
authors = ["Tristan Druyen <ek36g2vcc@mozmail.com>"]
|
||||
|
@ -20,7 +20,6 @@ syn = { version = "2.0", features = ["full"] }
|
|||
quote = "1.0"
|
||||
proc-macro2 = "1.0"
|
||||
glob = "0.3"
|
||||
macrotest = "1.1.0"
|
||||
regex = "1.11.1"
|
||||
|
||||
[dev-dependencies]
|
||||
|
@ -28,6 +27,7 @@ anyhow = "1.0.98"
|
|||
axum = "0.8.3"
|
||||
tokio = { version = "1.44.2", features = ["full"] }
|
||||
trybuild = "1.0.104"
|
||||
macrotest = "1.1.0"
|
||||
|
||||
[lints.clippy]
|
||||
pedantic = { level = "warn", priority = -1 }
|
||||
|
|
|
@ -172,36 +172,37 @@ pub fn route_registrations(
|
|||
|
||||
let method_registrations = methods_for_route(route_path);
|
||||
|
||||
if method_registrations.is_empty() {
|
||||
return quote! {
|
||||
compile_error!(concat!(
|
||||
"No routes defined in your route.rs's !\n",
|
||||
"ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)"
|
||||
));
|
||||
if !method_registrations.is_empty() {
|
||||
let first_method = &method_registrations[0];
|
||||
let first_method_ident = format_ident!("{}", first_method);
|
||||
|
||||
let mod_path_tokens = generate_mod_path_tokens(&mod_path);
|
||||
|
||||
let mut builder = quote! {
|
||||
axum::routing::#first_method_ident(#root_namespace_ident::#mod_path_tokens::#first_method_ident)
|
||||
};
|
||||
}
|
||||
|
||||
let first_method = &method_registrations[0];
|
||||
let first_method_ident = format_ident!("{}", first_method);
|
||||
for method in &method_registrations[1..] {
|
||||
let method_ident = format_ident!("{}", method);
|
||||
|
||||
let mod_path_tokens = generate_mod_path_tokens(&mod_path);
|
||||
builder = quote! {
|
||||
#builder.#method_ident(#root_namespace_ident::#mod_path_tokens::#method_ident)
|
||||
};
|
||||
}
|
||||
|
||||
let mut builder = quote! {
|
||||
axum::routing::#first_method_ident(#root_namespace_ident::#mod_path_tokens::#first_method_ident)
|
||||
};
|
||||
|
||||
for method in &method_registrations[1..] {
|
||||
let method_ident = format_ident!("{}", method);
|
||||
|
||||
builder = quote! {
|
||||
#builder.#method_ident(#root_namespace_ident::#mod_path_tokens::#method_ident)
|
||||
let registration = quote! {
|
||||
router = router.route(#axum_path, #builder);
|
||||
};
|
||||
route_registrations.push(registration);
|
||||
}
|
||||
|
||||
let registration = quote! {
|
||||
router = router.route(#axum_path, #builder);
|
||||
}
|
||||
if route_registrations.is_empty() {
|
||||
return quote! {
|
||||
compile_error!(concat!(
|
||||
"No routes defined in your route.rs's !\n",
|
||||
"Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)"
|
||||
));
|
||||
};
|
||||
route_registrations.push(registration);
|
||||
}
|
||||
|
||||
TokenStream::from_iter(route_registrations)
|
||||
|
|
|
@ -4,14 +4,14 @@ use std::{
|
|||
};
|
||||
|
||||
use syn::{
|
||||
parse::{Parse, ParseStream},
|
||||
parse_file,
|
||||
Ident,
|
||||
Item,
|
||||
LitStr,
|
||||
Result,
|
||||
Token,
|
||||
Visibility,
|
||||
parse::{Parse, ParseStream},
|
||||
parse_file,
|
||||
};
|
||||
|
||||
#[derive(Debug)]
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
error: No routes defined in your route.rs's !
|
||||
ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)
|
||||
Ensure that at least one `pub async fn` named after an HTTP verb is defined. (e.g. get, post, put, delete)
|
||||
--> tests/failures/no_routes.rs:6:1
|
||||
|
|
||||
6 | #[folder_router("../../../../tests/failures/no_routes", AppState)]
|
||||
|
|
Loading…
Add table
Reference in a new issue