shlogg · Early preview
Jeff Mitchell @sentinel1909

Rust Struct Initialization And Update Syntax Explained

Rust structs: field init shorthand, update syntax, tuple & unit structs explored. Learn how to initialize and update structs with ease, and discover the power of tuple and unit structs.

In a previous article, I introduced you to structs in Rust. Structs are flexible data structures that allow the grouping of fields together under one roof. Structs have a lot of capability. Let’s take a look at the things I didn’t cover last time out.

  
  
  The Field Init Shorthand

The fields of a struct can be initialized quickly by using the field init shorthand. Let’s see this through an example.
We’ll start by defining a struct to hold information about photos. Our struct will contain fields for an identifier, the date the photo was taken, the time the photo was taken, and the location...