]> git.cworth.org Git - rust-learning/commit
Parse the json file and deserialize it into a struct
authorCarl Worth <cworth@cworth.org>
Tue, 10 Mar 2026 02:36:37 +0000 (19:36 -0700)
committerCarl Worth <cworth@cworth.org>
Thu, 12 Mar 2026 04:14:55 +0000 (21:14 -0700)
commit1bc098d3437a50dc0b2570e05aa7dc8653469a08
tree0fc9a86788a8c5584db3291ed0467e6f2bd4240d
parent45b4fb4058591995c405572f8921086b79325077
Parse the json file and deserialize it into a struct

Where the struct only has a 'name' field so far.

This commit shows a few new things in rust that we haven't seen
previously:

* The "mod config" to depend on a module contained in config.rs

* The ? operator ("try operator") which unwraps a Result if it is_ok,
  and insteadd returns an error if it is not.

* Dependencies on rust packages, (serde_json, and serde with the
  "derive" feature") used for the JSON parsing and deserializing.

* The derive attribute (spelled "#[derive(...)]" used to automatically
  create implementations of the Debug and Deserialize traits for our
  struct. Debug isn't used here, but could be used by passing a
  ConfigFile value to println! or format! macros using a "{:?}" format
  specifier.

* A closure accepting a single parameter: |e| { ... }
Cargo.toml
src/config.rs [new file with mode: 0644]
src/main.rs