pub unsafe auto trait Forget { }forget_trait #165370)Expand description
Marks a type as “forgettable”, giving it the ability to be passed to
mem::forget, and other apis that may forget values.
A notable example of forgetting values, though slightly less obvious than
mem::forget, is using a value inside an Rc. Values inside Rcs or Arcs
can end up being forgotten as the result of a reference cycle.
By default, all types are assumed to be Forget. Similar to Sized, the
syntax T: ?Forget can be used to relax this bound for some type T. However,
Forget bounds are implicitly added in all cases unless explicitly opted out
of - notably, in trait definitions and associated types. If the forget_trait
feature is enabled, these can similarly be opted out of:
The explicit goal of mem::forget is not to run the destructor
of a value (i.e. its implementation of Drop).
As a dual to this, since ?Forget types cannot be forgotten, the destructors
of ?Forget types are guaranteed to be run.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".