Content-Length: 24155 | pFad | https://doc.rust-lang.org/std/string/../hash/../../std/string/../vec/../../error_codes/./E0040.html

E0040 - Error codes index

Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Error code E0040

It is not allowed to manually call destructors in Rust.

Erroneous code example:

struct Foo {
    x: i32,
}

impl Drop for Foo {
    fn drop(&mut self) {
        println!("kaboom");
    }
}

fn main() {
    let mut x = Foo { x: -7 };
    x.drop(); // error: explicit use of destructor method
}

It is unnecessary to do this since drop is called automatically whenever a value goes out of scope. However, if you really need to drop a value by hand, you can use the std::mem::drop function:

struct Foo {
    x: i32,
}
impl Drop for Foo {
    fn drop(&mut self) {
        println!("kaboom");
    }
}
fn main() {
    let mut x = Foo { x: -7 };
    drop(x); // ok!
}








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: https://doc.rust-lang.org/std/string/../hash/../../std/string/../vec/../../error_codes/./E0040.html

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy