3 ms·
It was weird for me at first, but actually Rust provides a great solution here. With https://github.com/DanielKeep/cargo-script https://github.com/DanielKeep/c
by the_duke 8y ago
It was weird for me at first, but actually Rust provides a great solution here.
With https://github.com/DanielKeep/cargo-script https://github.com/DanielKeep/cargo-script you can have single file Rust "scripts" with ecosystem dependencies.
When executing the file (via the cargo-script wrapper), dependencies are fetched and a binary is compiled on demand (and cached for re-runs).
It's pretty awesome for scripts where type safety is important.
#!/usr/bin/env run-cargo-script
//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest. Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```
extern crate time;
fn main() {
println!("{}", time::now().rfc822z());
}
Then you can just execute it with ./my-script, which will download dependencies, compile and execute.
- dmux 8y agoLikewise with Apache Groovy, which has optional typing: #!/usr/bin/env groovy // @Grab annotation won't work in scripts import static groovy.grape.Grape.grab grab(group: 'org.apache.commons', module: 'commons-csv', version: '1.5') println "Starting to parse CSV"
- blattimwind 8y agoKotlin can do it, too: https://github.com/holgerbrandl/kscript https://github.com/holgerbrandl/kscript
- arcticbull 8y agoThanks for sharing that, I had no idea. You just improved my day.
- deleted 8y ago[deleted]