loco-rs / loco

🚂 🦀 The one-person framework for Rust for side-projects and startups
https://loco.rs
Apache License 2.0
5.01k stars 206 forks source link

consider moving main.rs back under src #875

Open joshka opened 2 days ago

joshka commented 2 days ago

Consider moving the main.rs file out from under bin back into the src folder and removing the lib.rs file. While hiding away some of the complexity of rust is kind of a good thing, this is one of those places where it may confuse beginner rustaceans, and annoy more experienced ones who might have need to do application startup tasks that don't neatly fit into the Application hooks approach.

jondot commented 1 day ago

Interesting! I guess you mean for a newly generated app. This makes sense like you're saying since we're resulting in a binary app.

We've had to circumvent another issue, where the result was having to have both a main.rs and a tool.rs. Since Windows does not allow to overwrite a binary that is actually running (a binary that overwrites itself), we had to use a side-stepping method by including a second binary called tool.rs that will overwrite the first, and this frequently happens during code generation.

I'm wondering how this might look like if you have to ship a source tree with two binaries, WDYT?

joshka commented 1 day ago

Interesting! I guess you mean for a newly generated app. This makes sense like you're saying since we're resulting in a binary app.

yep.

I'm wondering how this might look like if you have to ship a source tree with two binaries, WDYT?

I think you still end up with main in the root, but perhaps have the tool under src/bin. This makes it more clear that the tool is just for replacing main when automatically updating. You might even scope that down so it's obviously for that purpose rather than just being an exact copy of main.rs. It was unclear to me why tool existed, but the explanation makes sense.