From 698f8c2f01ea549d77d7dc3338a12e04c11057b9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:02:58 +0200 Subject: Adding upstream version 1.64.0+dfsg1. Signed-off-by: Daniel Baumann --- .../ch15-smart-pointers/listing-15-15/Cargo.lock | 6 ++++++ .../ch15-smart-pointers/listing-15-15/Cargo.toml | 6 ++++++ .../ch15-smart-pointers/listing-15-15/output.txt | 13 +++++++++++++ .../ch15-smart-pointers/listing-15-15/src/main.rs | 20 ++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.lock create mode 100644 src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.toml create mode 100644 src/doc/book/listings/ch15-smart-pointers/listing-15-15/output.txt create mode 100644 src/doc/book/listings/ch15-smart-pointers/listing-15-15/src/main.rs (limited to 'src/doc/book/listings/ch15-smart-pointers/listing-15-15') diff --git a/src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.lock b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.lock new file mode 100644 index 000000000..eb8a2817a --- /dev/null +++ b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.lock @@ -0,0 +1,6 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +[[package]] +name = "drop-example" +version = "0.1.0" + diff --git a/src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.toml b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.toml new file mode 100644 index 000000000..1e4c99481 --- /dev/null +++ b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "drop-example" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/src/doc/book/listings/ch15-smart-pointers/listing-15-15/output.txt b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/output.txt new file mode 100644 index 000000000..a38c9ccb7 --- /dev/null +++ b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/output.txt @@ -0,0 +1,13 @@ +$ cargo run + Compiling drop-example v0.1.0 (file:///projects/drop-example) +error[E0040]: explicit use of destructor method + --> src/main.rs:16:7 + | +16 | c.drop(); + | --^^^^-- + | | | + | | explicit destructor calls not allowed + | help: consider using `drop` function: `drop(c)` + +For more information about this error, try `rustc --explain E0040`. +error: could not compile `drop-example` due to previous error diff --git a/src/doc/book/listings/ch15-smart-pointers/listing-15-15/src/main.rs b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/src/main.rs new file mode 100644 index 000000000..ff3b391a9 --- /dev/null +++ b/src/doc/book/listings/ch15-smart-pointers/listing-15-15/src/main.rs @@ -0,0 +1,20 @@ +struct CustomSmartPointer { + data: String, +} + +impl Drop for CustomSmartPointer { + fn drop(&mut self) { + println!("Dropping CustomSmartPointer with data `{}`!", self.data); + } +} + +// ANCHOR: here +fn main() { + let c = CustomSmartPointer { + data: String::from("some data"), + }; + println!("CustomSmartPointer created."); + c.drop(); + println!("CustomSmartPointer dropped before the end of main."); +} +// ANCHOR_END: here -- cgit v1.2.3