diff --git a/src/custom_types/structs.md b/src/custom_types/structs.md index eccd30eb2d..8e86831947 100644 --- a/src/custom_types/structs.md +++ b/src/custom_types/structs.md @@ -37,6 +37,12 @@ struct Rectangle { bottom_right: Point, } +// Struct with named fields can have default values +struct Command { + command: String, + arguments: Vec = Vec::new(), +} + fn main() { // Create struct with field init shorthand let name = String::from("Peter"); @@ -70,6 +76,9 @@ fn main() { bottom_right: bottom_right, }; + // Instantiate a `Command` with only required fields specified + let command = Command { command: String::from("ls"), .. }; + // Instantiate a unit struct let _unit = Unit;