summaryrefslogtreecommitdiffstats
path: root/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions
diff options
context:
space:
mode:
Diffstat (limited to 'src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions')
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.lock5
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.toml6
-rw-r--r--src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/src/main.rs20
3 files changed, 31 insertions, 0 deletions
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.lock b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.lock
new file mode 100644
index 000000000..4aabe7da6
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.lock
@@ -0,0 +1,5 @@
+# This file is automatically @generated by Cargo.
+# It is not intended for manual editing.
+[[package]]
+name = "rectangles"
+version = "0.1.0"
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.toml b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.toml
new file mode 100644
index 000000000..4a279a450
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/Cargo.toml
@@ -0,0 +1,6 @@
+[package]
+name = "rectangles"
+version = "0.1.0"
+edition = "2021"
+
+[dependencies]
diff --git a/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/src/main.rs b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/src/main.rs
new file mode 100644
index 000000000..47fedc552
--- /dev/null
+++ b/src/doc/book/listings/ch05-using-structs-to-structure-related-data/no-listing-03-associated-functions/src/main.rs
@@ -0,0 +1,20 @@
+#[derive(Debug)]
+struct Rectangle {
+ width: u32,
+ height: u32,
+}
+
+// ANCHOR: here
+impl Rectangle {
+ fn square(size: u32) -> Self {
+ Self {
+ width: size,
+ height: size,
+ }
+ }
+}
+// ANCHOR_END: here
+
+fn main() {
+ let sq = Rectangle::square(3);
+}