I was writing a few small scripts in Rust. These can be run via a command like
$ rustc dosomething.rs && ./dosomething
These work great. However, I ran into a case where I needed to use regexes. I began the script with extern crate regex;
It appears that this means I need to run my script via Cargo. The only way I managed to run this tiny script using regexes was to force my script into its own directory, with the following structure:
.
├── Cargo.toml
└── src
└── main.rs
I loaded up Cargo.toml
with
[package]
name = "wordcount"
version = "0.0.1"
[dependencies]
regex = "0.1"
and dutifully ran cargo build
and got my running executable.
However, when computing the disk space used by the Cargo artifacts I found them to be made up of 17 files, 21 directories, and 23 megabytes used.
Now this is perfectly fine when running large applications; I've seem small Java applications where Maven downloads so many jars that 23M is microscopic.
I'm simply wondering whether there is not some other way to write scripts using regular expressions in Rust. (Yes, I do want regexes because of the ease of using \pL
.)
Is there built-in support for regular expressions in Rust or some way to keep my wordcount script in the same directory as my other scripts? Is there some analog of the -L
flag, perhaps?
Is there built-in support for regular expressions in Rust
No, but the regex crate will (probably) be the standard (out of std
?) regex library for Rust.
or some way to keep my wordcount script in the same directory as my other scripts?
A Cargo project can have more than one executable. Just put each main file in src/bin
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With