-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Open
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
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.)
- ACP: ACP: Add core::mem::WithDrop to associate a custom drop fn with some data libs-team#622
- Implementation: Add
core::mem::DropGuard#144236 - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- What should the name of the type be?
DropGuard,WithDropandDropperwere some of the preferred options raised in the 2025-07-22 T-Libs-API call. - Should the impl have a
Cloneimpl? This can always be added in the future, but should be discussed further prior to stabilization. - Should the
Debugimpl be transparent? This can always be added in the future, but should be discussed further prior to stabilization. - What should the name of the method be for "take ownership of the value without running the destructor"? The name current name for this method is
into_inner, but other names have been proposed, including:disarm,defuse,disable, andskip_drop.
Footnotes
orzogc and zopsicle
Metadata
Metadata
Assignees
Labels
C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.