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
Feature gate:
#![feature(drop_guard)]This is a tracking issue for the
core::mem::DropGuardAPI: a helper type that makes it easy to createimpl Dropdestructors inline.Public API
Steps / History
(Remember to update the
S-tracking-*label when checking boxes.)core::mem::DropGuard#144236DropGuard::into_innertoDropGuard::dismiss#148589 (comment)Unresolved Questions
DropGuard,WithDropandDropperwere some of the preferred options raised in the 2025-07-22 T-Libs-API call.Cloneimpl? This can always be added in the future, but should be discussed further prior to stabilization.Debugimpl be transparent? This can always be added in the future, but should be discussed further prior to stabilization.into_inner, but other names have been proposed, including:disarm,defuse,disable, andskip_drop.Footnotes
https://std-dev-guide.rust-lang.org/feature-lifecycle/stabilization.html ↩