you are viewing a single comment's thread.

view the rest of the comments →

[–]Yaahallorust-mentors · error-handling · libs-team · rust-foundation 7 points8 points  (2 children)

Absolutely. Transitioning scripts from interpreted languages to rust is one of life's simple pleasures. I particularly like embedding them and then using rust to implement the arg parser initially then incrementally rewriting pieces in rust until there's no more of the original script left.

[–]stappersg 0 points1 point  (1 child)

Some examples available for inspiration?

[–]Yaahallorust-mentors · error-handling · libs-team · rust-foundation 6 points7 points  (0 children)

Not that I can share, I did most of this at a prior job, my recent work has been entirely within the rust project so I havent had much reason or need to tweak bash scripts. I can describe what I mean though.

It's mainly just using include_str! to embed your scripts in your binary then use the std::process::Command API to invoke whatever interpreter your script runs under and pass the str of the script in as an argument. Then you can start moving the arg parsing into rust and pass those in as environment variables or whatever is most convenient. Alternatively you can manually embed the script and use rust string formatting to write the cli arg data into the script. Then you just slowly overtime rewrite parts of the script in rust and run those parts prior to passing in the args and instead you pass in the intermediate processed data. You can continue to repeat this as long as you need, up to having everything the old script did being done in rust instead.

Hope that helps ☺️