async_drop.rs - source
Description: Source of the Rust file `library/core/src/future/async_drop.rs`.

#
core/future/
async_drop.rs

    1#![unstable(feature = "async_drop", issue = "126482")]
    2
    3#[allow(unused_imports)]
    4use core::future::Future;
    5
    6#[allow(unused_imports)]
    7use crate::pin::Pin;
    8#[allow(unused_imports)]
    9use crate::task::{Context, Poll};
    10
    11/// Async version of Drop trait.
    12///
    13/// When a value is no longer needed, Rust will run a "destructor" on that value.
    14/// The most common way that a value is no longer needed is when it goes out of
    15/// scope. Destructors may still run in other circumstances, but we're going to
    16/// focus on scope for the examples here. To learn about some of those other cases,
    17/// please see [the reference] section on destructors.
    18///
    19/// [the reference]: https://doc.rust-lang.org/reference/destructors.html
    20///
    21/// ## `Copy` and ([`Drop`]|`AsyncDrop`) are exclusive
    22///
    23/// You cannot implement both [`Copy`] and ([`Drop`]|`AsyncDrop`) on the same type. Types that
    24/// are `Copy` get implicitly duplicated by the compiler, making it very
    25/// hard to predict when, and how often destructors will be executed. As such,
    26/// these types cannot have destructors.
    27#[unstable(feature = "async_drop", issue = "126482")]
    28#[lang = "async_drop"]
    29pub trait AsyncDrop {
    30    /// Executes the async destructor for this type.
    31    ///
    32    /// This method is called implicitly when the value goes out of scope,
    33    /// and cannot be called explicitly.
    34    ///
    35    /// When this method has been called, `self` has not yet been deallocated.
    36    /// That only happens after the method is over.
    37    ///
    38    /// # Panics
    39    #[allow(async_fn_in_trait)]
    40    async fn drop(self: Pin<&mut Self>);
    41}
    42
    43/// Async drop.
    44#[unstable(feature = "async_drop", issue = "126482")]
    45#[lang = "async_drop_in_place"]
    46pub async unsafe fn async_drop_in_place<T: ?Sized>(_to_drop: *mut T) {
    47    // Code here does not matter - this is replaced by the
    48    // real implementation by the compiler.
    49}