summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference')
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.lock6
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs15
3 files changed, 27 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.lock b/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.lock
new file mode 100644
index 000000000..2aa4918e5
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.lock
@@ -0,0 +1,6 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "ownership"
+version = "0.1.0"
+
diff --git a/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.toml b/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.toml
new file mode 100644
index 000000000..e8847526d
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "ownership"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs b/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs
new file mode 100644
index 000000000..fd32a5fc9
--- /dev/null
+++ b/src/doc/book/listings/ch04-understanding-ownership/no-listing-07-reference/src/main.rs
@@ -0,0 +1,15 @@
+// ANCHOR: all
+fn main() {
+ // ANCHOR: here
+ let s1 = String::from("hello");
+
+ let len = calculate_length(&s1);
+ // ANCHOR_END: here
+
+ println!("The length of '{}' is {}.", s1, len);
+}
+
+fn calculate_length(s: &String) -> usize {
+ s.len()
+}
+// ANCHOR_END: all