This is a small example of how to read a file in Rust. The project is my solution to the first assignment of the course Rust Programming Specialization on Coursera by Alfredo Deza at Duke University.
See ASSIGNMENT.md for the original assignment.
- Read a file in Rust
- Handle errors in Rust
- Familiarize with the
Result
type,match
andunwrap
in Rust - Have fun with Rust :)
I've called it json_reader, since I wanted to experiment with the serde_json
crate
and have a json pretty print of the file content.
serde_json
for pretty printing the json content of the file (v.1.0.116)dialoguer
for user interaction (v.0.11.0)
Later I substituted makefile
with just
, a Rust native replacement and much more powerful tool.
- Just Docs - (github repo)
.
├── Cargo.lock
├── Cargo.toml
├── CHANGELOG.md
├── cliff.toml # Configuration file for the Changelog
├── LICENSE # MIT License
├── Justfile # Rust native replacement for makefile
├── README.md
├── src # Source code
│ ├── fs_manager.rs # File system manager (open and read files)
│ ├── interactive.rs # User interaction with dialoguer
│ ├── main.rs # Main entry point
│ └── utils.rs # Utility functions
├── target # Rust build directory
└── test.json # Test file for json pretty print
- Rust installed
- Cargo installed
- Just installed (optional, you can also use the cargo commands)
# Clone the repository
git clone
# Change directory
cd rust-json-reader
# Build the project
cargo build --release
# Run the project
./target/release/json_reader [<path_to_file>] # If no path is provided, it will read the current directory
- Show help message
./target/release/json_reader [--help | -h]