Skip to content

amasotti/rust-json-reader

Repository files navigation

Rust file reader

Rust Build

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.

Learning objectives

  • Read a file in Rust
  • Handle errors in Rust
  • Familiarize with the Result type, match and unwrap 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.

Crates I've experimented with

  • 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.

Structure

.
├── 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

How to run

Prerequisites

  • Rust installed
  • Cargo installed
  • Just installed (optional, you can also use the cargo commands)

Steps

# 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]

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •