a small run-length encoding and decoding CLI written in Rust because apparently i needed another excuse to make a command-line program
rle-tools is a small interactive CLI for encoding and decoding text using run-length encoding (RLE).
i made this mainly to practice working with:
- string processing
- iterators and character handling
Result-based error handling- CLI input and control flow
- splitting a Rust project into modules
- writing and testing reusable encoding and decoding logic
the program provides separate modes for encoding and decoding, with input validation and recoverable errors for invalid input. . .
- run-length encoding (yes!)
- run-length decoding (yes!)
- interactive CLI (eh??)
- input validation (uhuh...)
- error handling (erm...)
run-length encoding represents consecutive repeated characters using a count followed by the character!!
for example:
aaabbccccdaa
↓
3a2b4c1d2a
decoding reverses the process:
3a2b4c1d2a
↓
aaabbccccdaa
another example:
beepboop
↓
1b2e1p1b2o1p
a normal session looks like this:
Select:
1. Encode
2. Decode
3. Exit
--> 1
Enter '__exit' to exit.
Enter anything else to proceed with encoding.
Enter something: beepboop
The encoded result is: 1b2e1p1b2o1p
Enter something: __exit
Exiting...
Select:
1. Encode
2. Decode
3. Exit
--> 2
Enter '__exit' to exit.
Enter anything else to proceed with decoding.
Enter something: 1b2e1p1b2o1p
The decoded result is: beepboop
Enter something: __exit
Exiting...
Select:
1. Encode
2. Decode
3. Exit
--> 3
Goodbye!invalid input is handled without terminating the program:
Enter something: b1pweo
[Error]: Raw input string for encoding must not contain digits.
Enter something: aaaaaa
The encoded result is: 6ai wanted a relatively small Rust project that still required me to think about how to structure an actual application instead of putting everything inside main.rs
it also gave me an excuse to work with Result and error propagation while implementing both the encoder and decoder myself !
- Rust
- Cargo
clone the repository and enter the project directory:
git clone https://github.com/jayywashere/rle-tools
cd rle-toolsrun the program:
cargo runrun the tests:
cargo testSee LICENSE.