From: Ian Jackson Date: Mon, 28 Mar 2022 01:00:22 +0000 (+0100) Subject: actix routing: Use a conventional prefix for route "function" names X-Git-Tag: otter-1.0.0~89 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=c0ede0a5a1e6b14deea4682c7ff67820dd2c3be0;p=otter.git actix routing: Use a conventional prefix for route "function" names Signed-off-by: Ian Jackson --- diff --git a/daemon/main.rs b/daemon/main.rs index 4cffdb28..7555127a 100644 --- a/daemon/main.rs +++ b/daemon/main.rs @@ -162,13 +162,13 @@ struct LoadingRenderContext<'r> { } #[route("/", method="GET", method="HEAD")] #[throws(FER)] -async fn loading_p(ia: PlayerQueryString, +async fn r_loading_p(ia: PlayerQueryString, templates: Data) -> Template { loading(None, ia, templates)? } #[route("/{layout}", method="GET", method="HEAD")] #[throws(FER)] -async fn loading_l(layout: Path>, +async fn r_loading_l(layout: Path>, ia: PlayerQueryString, templates: Data) -> Template { @@ -285,7 +285,7 @@ struct UpdatesParams { #[route("/_/updates", method="GET", wrap="updates_cors()")] #[throws(FER)] -async fn updates_route(query: Query) -> impl Responder { +async fn r_updates(query: Query) -> impl Responder { let UpdatesParams { ctoken, gen } = query.into_inner(); let gen = Generation(gen); let iad = ctoken.0.i; @@ -307,7 +307,7 @@ async fn updates_route(query: Query) -> impl Responder { // is last in the list. #[route("/_/{leaf}", method="GET", method="HEAD")] #[throws(io::Error)] -async fn resource(leaf: Path>) -> impl Responder { +async fn r_resource(leaf: Path>) -> impl Responder { let leaf = leaf.into_inner().0; let path = match leaf.locn { RL::Main => format!("{}/{}", config().template_dir, leaf.safe_leaf), @@ -342,7 +342,7 @@ impl ResponseError for BundleDownloadError { #[route("/_/bundle/{instance}/{id}", method="GET", method="HEAD")] #[throws(BundleDownloadError)] -async fn bundle_route(path: Path<( +async fn r_bundle(path: Path<( Parse, Parse, )>, token: WholeQueryString @@ -501,13 +501,17 @@ async fn main() -> Result<(),StartupError> { let app = actix_web::App::new() .service(services![ - loading_l, - loading_p, - bundle_route, - updates_route, + // We name these r_* because actix's #[route] macro defines + // them as unit structs, not functions or data values. The + // result is that they are *type names* which makes them + // impossible to locally rebind. + r_loading_l, + r_loading_p, + r_bundle, + r_updates, session::routes(), api::routes(), - resource, // Must come after more specific URL paths + r_resource, // Must come after more specific URL paths ]) .app_data(json_config) .app_data(templates.clone()) diff --git a/daemon/session.rs b/daemon/session.rs index 2cf74441..b34b83e4 100644 --- a/daemon/session.rs +++ b/daemon/session.rs @@ -71,7 +71,7 @@ pub struct SessionForm { } #[post("/_/session/{layout}")] #[throws(FER)] -pub async fn session(form: Json, +pub async fn r_session(form: Json, templates: Data, layout: Path>) -> Template { @@ -262,6 +262,6 @@ fn session_inner(form: Json, pub fn routes() -> impl HttpServiceFactory { services![ - session, + r_session, ] }