From 0bf558dd5b0703367c15aef20aec8004d32969a7 Mon Sep 17 00:00:00 2001 From: Giang Nguyen Date: Mon, 16 Jan 2017 16:49:44 +0700 Subject: [PATCH 1/2] Add example struct field init shorthand --- examples/custom_types/structs/structs.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/examples/custom_types/structs/structs.rs b/examples/custom_types/structs/structs.rs index d8c538f439..6fb317b0ff 100644 --- a/examples/custom_types/structs/structs.rs +++ b/examples/custom_types/structs/structs.rs @@ -1,3 +1,11 @@ +// Enable feature field init shorthand +#![feature(field_init_shorthand)] +#[derive(Debug)] +struct Person<'a> { + name: &'a str, + age: u8 +} + // A unit struct struct Nil; @@ -18,6 +26,15 @@ struct Rectangle { } fn main() { + // Create struct with field init shorthand + let name = "Peter"; + let age = 27; + let peter = Person { name, age }; + + // Print debug struct + println!("{:?}", peter); + + // Instantiate a `Point` let point: Point = Point { x: 0.3, y: 0.4 }; From 87de92eb10bc6e868602f07515c29bb359680535 Mon Sep 17 00:00:00 2001 From: Steve Klabnik Date: Thu, 8 Jun 2017 13:56:49 -0400 Subject: [PATCH 2/2] remove feature flag --- examples/custom_types/structs/structs.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/examples/custom_types/structs/structs.rs b/examples/custom_types/structs/structs.rs index 6fb317b0ff..3332f88eab 100644 --- a/examples/custom_types/structs/structs.rs +++ b/examples/custom_types/structs/structs.rs @@ -1,5 +1,3 @@ -// Enable feature field init shorthand -#![feature(field_init_shorthand)] #[derive(Debug)] struct Person<'a> { name: &'a str,