Can't use reexported function with same name as file in route!
. Is this intended?
#1801
-
Hello, I'm trying to use a reexported function, with the same name as the file it is contained in, in a I have a function The compiler show this error message:
If I do that, it works (after changing the visibility of Changing the name of the function to something that's different from the This is the code: https://github.com/arctic-alpaca/zero2prod_rocket This is the similar actix code: https://github.com/LukeMathWalker/zero-to-production/tree/root-chapter-03-part1 I'd appreciate any input why this doesn't compile. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
No, it's not intentional. But I'm also not sure if it's too easily avoidable. The problem does have to do with the name clash:
At this point you would have a module, Incidentally, this is one of a few reasons in favor of avoiding
In this actix-web version, it looks like you attach the routes in a way that does not use any macros. In Rocket's case, several important features (including error messages for route handlers) depend a lot on the macros and I don't think we could readily provide a similar option. IIRC actix-web also has For what it's worth I generally recommend not repeating names like |
Beta Was this translation helpful? Give feedback.
No, it's not intentional. But I'm also not sure if it's too easily avoidable.
The problem does have to do with the name clash:
At this point you would have a module,
routes
, with these items in it:mod health_check;
,fn health_check
, andstruct health_check
. (struct health_check
was generated by rocket). But because that struct has the same name as the modulehealth_check
,pub use health_check::*;
does not reexport it. You can see this behavior in this playground example: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=2ba98a811cf614dd…