Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion core/codegen/src/attribute/route/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ fn codegen_route(route: Route) -> Result<TokenStream> {
let rank = Optional(route.attr.rank);
let format = Optional(route.attr.format.as_ref());

let route_name = match &route.attr.name {
Some(name) => quote! { #name },
None => {
quote! { stringify!(#handler_fn_name) }
}
};

Ok(quote! {
#handler_fn

Expand Down Expand Up @@ -361,7 +368,7 @@ fn codegen_route(route: Route) -> Result<TokenStream> {
}

#_route::StaticInfo {
name: stringify!(#handler_fn_name),
name: #route_name,
method: #method,
uri: #uri,
handler: monomorphized_function,
Expand Down Expand Up @@ -419,6 +426,7 @@ fn incomplete_route(
data: method_attribute.data,
format: method_attribute.format,
rank: method_attribute.rank,
name: method_attribute.name,
};

codegen_route(Route::from(attribute, function)?)
Expand Down
2 changes: 2 additions & 0 deletions core/codegen/src/attribute/route/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct Attribute {
pub data: Option<SpanWrapped<Dynamic>>,
pub format: Option<MediaType>,
pub rank: Option<isize>,
pub name: Option<String>,
}

/// The parsed `#[method(..)]` (e.g, `get`, `put`, etc.) attribute.
Expand All @@ -57,6 +58,7 @@ pub struct MethodAttribute {
pub data: Option<SpanWrapped<Dynamic>>,
pub format: Option<MediaType>,
pub rank: Option<isize>,
pub name: Option<String>,
}

#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions core/lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ mod phase;
#[doc(inline)] pub use crate::config::Config;
#[doc(inline)] pub use crate::catcher::Catcher;
#[doc(inline)] pub use crate::route::Route;
#[doc(inline)] pub use crate::router::Router;
#[doc(hidden)] pub use either::Either;
#[doc(inline)] pub use phase::{Phase, Build, Ignite, Orbit};
#[doc(inline)] pub use error::Error;
Expand Down
1 change: 1 addition & 0 deletions core/lib/src/router/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ mod router;
mod collider;
mod matcher;

pub use router::Router;
pub(crate) use router::*;
pub(crate) use collider::*;
2 changes: 1 addition & 1 deletion core/lib/src/router/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{Route, Catcher};
use crate::router::Collide;

#[derive(Debug, Default)]
pub(crate) struct Router {
pub struct Router {
routes: HashMap<Method, Vec<Route>>,
catchers: HashMap<Option<u16>, Vec<Catcher>>,
}
Expand Down