这是indexloc提供的服务,不要输入任何密码
Skip to content

Tracking Issue for core::mem::DropGuard #144426

@yoshuawuyts

Description

@yoshuawuyts

Feature gate: #![feature(drop_guard)]

This is a tracking issue for the core::mem::DropGuard API: a helper type that makes it easy to create impl Drop destructors inline.

Public API

#![feature(drop_guard)]

use std::mem::DropGuard;

{
    // Create a new guard around a string that will
    // print its value when dropped.
    let s = String::from("Chashu likes tuna");
    let mut s = DropGuard::new(s, |s| println!("{s}"));

    // Modify the string contained in the guard.
    s.push_str("!!!");

    // The guard will be dropped here, printing:
    // "Chashu likes tuna!!!"
}

Steps / History

(Remember to update the S-tracking-* label when checking boxes.)

Unresolved Questions

  • What should the name of the type be? DropGuard, WithDrop and Dropper were some of the preferred options raised in the 2025-07-22 T-Libs-API call.
  • Should the impl have a Clone impl? This can always be added in the future, but should be discussed further prior to stabilization.
  • Should the Debug impl be transparent? This can always be added in the future, but should be discussed further prior to stabilization.

Footnotes

  1. https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCS-tracking-unimplementedStatus: The feature has not been implemented.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions