summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct')
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.toml8
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt31
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/src/main.rs15
4 files changed, 60 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.lock b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.lock
new file mode 100644
index 000000000..bede081a0
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "structs"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.toml b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.toml
new file mode 100644
index 000000000..d36dbc1d3
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "structs"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt
new file mode 100644
index 000000000..e28da599c
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/output.txt
@@ -0,0 +1,31 @@
+$ cargo run
+ Compiling structs v0.1.0 (file:///projects/structs)
+error[E0106]: missing lifetime specifier
+ --> src/main.rs:3:15
+ |
+3 | username: &str,
+ | ^ expected named lifetime parameter
+ |
+help: consider introducing a named lifetime parameter
+ |
+1 ~ struct User<'a> {
+2 | active: bool,
+3 ~ username: &'a str,
+ |
+
+error[E0106]: missing lifetime specifier
+ --> src/main.rs:4:12
+ |
+4 | email: &str,
+ | ^ expected named lifetime parameter
+ |
+help: consider introducing a named lifetime parameter
+ |
+1 ~ struct User<'a> {
+2 | active: bool,
+3 | username: &str,
+4 ~ email: &'a str,
+ |
+
+For more information about this error, try `rustc --explain E0106`.
+error: could not compile `structs` due to 2 previous errors
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/src/main.rs b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/src/main.rs
new file mode 100644
index 000000000..96092d042
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-02-reference-in-struct/src/main.rs
@@ -0,0 +1,15 @@
+struct User {
+ active: bool,
+ username: &str,
+ email: &str,
+ sign_in_count: u64,
+}
+
+fn main() {
+ let user1 = User {
+ email: "someone@example.com",
+ username: "someusername123",
+ active: true,
+ sign_in_count: 1,
+ };
+}