chiark / gitweb /
actix routing: Use a conventional prefix for route "function" names
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Mar 2022 01:00:22 +0000 (02:00 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Mon, 28 Mar 2022 01:00:44 +0000 (02:00 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
daemon/main.rs
daemon/session.rs

index 4cffdb28a322d8db886a438780c3f717c64ebae9..7555127a269411e73ab573c5a540b16e5744633e 100644 (file)
@@ -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<Templates>) -> Template {
   loading(None, ia, templates)?
 }
 #[route("/{layout}", method="GET", method="HEAD")]
 #[throws(FER)]
-async fn loading_l(layout: Path<Parse<AbbrevPresentationLayout>>,
+async fn r_loading_l(layout: Path<Parse<AbbrevPresentationLayout>>,
                    ia: PlayerQueryString,
                    templates: Data<Templates>)
              -> Template {
@@ -285,7 +285,7 @@ struct UpdatesParams {
 
 #[route("/_/updates", method="GET", wrap="updates_cors()")]
 #[throws(FER)]
-async fn updates_route(query: Query<UpdatesParams>) -> impl Responder {
+async fn r_updates(query: Query<UpdatesParams>) -> 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<UpdatesParams>) -> impl Responder {
 // is last in the list.
 #[route("/_/{leaf}", method="GET", method="HEAD")]
 #[throws(io::Error)]
-async fn resource(leaf: Path<Parse<CheckedResourceLeaf>>) -> impl Responder {
+async fn r_resource(leaf: Path<Parse<CheckedResourceLeaf>>) -> 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<InstanceName>,
   Parse<bundles::Id>,
 )>, token: WholeQueryString<AssetUrlToken, BundleDownloadError>
@@ -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())
index 2cf74441e3e749662043c7c25a2b99c5c3a2347c..b34b83e4c88e21688047311bb1cc5ba85e8f0cb3 100644 (file)
@@ -71,7 +71,7 @@ pub struct SessionForm {
 }
 #[post("/_/session/{layout}")]
 #[throws(FER)]
-pub async fn session(form: Json<SessionForm>,
+pub async fn r_session(form: Json<SessionForm>,
                  templates: Data<Templates>,
                layout: Path<Parse<PresentationLayout>>)
            -> Template {
@@ -262,6 +262,6 @@ fn session_inner(form: Json<SessionForm>,
 
 pub fn routes() -> impl HttpServiceFactory {
   services![
-    session,
+    r_session,
   ]
 }