std::mem::drop - Rust
Description: API documentation for the Rust `drop` fn in crate `std`.
Keywords: rust, rustlang, rust-lang, drop

# 1.0.0[−][src]Function std::mem::drop

    pub fn drop<T>(_x: T)

Disposes of a value.

This does call the argument's implementation of `Drop`.

This effectively does nothing for types which implement `Copy`, e.g. integers. Such values are copied and then moved into the function, so the value persists after this function call.

This function is not magic; it is literally defined as

    pub fn drop<T>(_x: T) { }Run

Because `_x` is moved into the function, it is automatically dropped before the function returns.

# Examples

Basic usage:

    let v = vec![1, 2, 3];

    drop(v); // explicitly drop the vectorRun

Since `RefCell` enforces the borrow rules at runtime, `drop` can release a `RefCell` borrow:

    use std::cell::RefCell;

    let x = RefCell::new(1);

    let mut mutable_borrow = x.borrow_mut();
    *mutable_borrow = 1;

    drop(mutable_borrow); // relinquish the mutable borrow on this slot

    let borrow = x.borrow();
    println!("{}", *borrow);Run

Integers and other types implementing `Copy` are unaffected by `drop`.

    #[derive(Copy, Clone)]
    struct Foo(u8);

    let x = 1;
    let y = Foo(2);
    drop(x); // a copy of `x` is moved and dropped
    drop(y); // a copy of `y` is moved and dropped

    println!("x: {}, y: {}", x, y.0); // still availableRun