I've been looking at rust for a while, but I thought I'd try to get some "proper" experience, by converting one of my existing projects into Rust. The project is a Windows "launcher" for Python scripts, it looks for a script alongside the executable, finds an appropriate Python interpreter and runs the script with it.
It's not a particularly complex program, but it's a pain in C because of all the filename manipulations (as well as the usual hassles of memory management, etc).
The code is here: GitHub - pfmoore/pylaunch2
I was pleasantly surprised at how easy it was to get the program working in Rust, and while it took me a little while to work out a good structure (I want two executables, one a console-mode Windows executable and one a GUI-mode executable), I got something working super fast. I'm now looking at how to make it mode "idiomatic", and sort out any rough edges where I could be doing things better.
I used the anyhow crate for errors, mainly because it gave me nice errors with very little effort. I'd be fine with hearing about how I could improve this, but honestly, it's good enough for me as it is.
Particular things I am unhappy with:
- Having to hard-code the project name in
use pylaunch::{...}
statements in the binaries. I expected to use a relative name there, but I couldn't get it to work. - The whole
Config
struct. It feels messy, with all the'static
lifetime annotations. But I really wanted to avoid unnecessary copies of strings (yes, I know, premature optimisation...) as everything here is entirely static - it's basically just encapsulating the "magic values" that distinguish the GUI and the console versions of the code. Someday I may add the ability to read a "config" from a file, but right now I have no need for that, and I'd like to prioritise the basic case of static values.
And obviously, hints on any general style issues where someone with more experience would write things differently would be much appreciated.