mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
17 lines
390 B
Rust
17 lines
390 B
Rust
struct PrintOnDrop<'a>(&'a str);
|
|
|
|
impl Drop for PrintOnDrop<'_> {
|
|
fn drop(&mut self) {
|
|
println!("printint: {}", self.0);
|
|
}
|
|
}
|
|
|
|
use std::collections::BTreeMap;
|
|
use std::iter::FromIterator;
|
|
|
|
fn main() {
|
|
let s = String::from("Hello World!");
|
|
let _map = BTreeMap::from_iter([((), PrintOnDrop(&s))]);
|
|
drop(s); //~ ERROR cannot move out of `s` because it is borrowed
|
|
}
|