You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#[stable(feature = "manually_drop", since = "1.20.0")]#[lang = "manually_drop"]#[derive(Copy,Clone,Debug,Default,PartialEq,Eq,PartialOrd,Ord,Hash)]#[repr(transparent)]pubstructManuallyDrop<T: ?Sized>{value:T,}impl<T>ManuallyDrop<T>{#[must_use = "if you don't need the wrapper, you can use `mem::forget` instead"]#[stable(feature = "manually_drop", since = "1.20.0")]#[rustc_const_stable(feature = "const_manually_drop", since = "1.36.0")]#[inline(always)]pubconstfnnew(value:T) -> ManuallyDrop<T>{ManuallyDrop{ value }}}impl<T: ?Sized>ManuallyDrop<T>{#[stable(feature = "manually_drop", since = "1.20.0")]#[inline]pubunsafefndrop(slot:&mutManuallyDrop<T>){// SAFETY: we are dropping the value pointed to by a mutable reference// which is guaranteed to be valid for writes.// It is up to the caller to make sure that `slot` isn't dropped again.unsafe{ ptr::drop_in_place(&mut slot.value)}}}
已不再是联合体定义
The text was updated successfully, but these errors were encountered:
ManuallyDrop
源码代码过期书中的
ManuallyDrop
源码及描述ManuallyDrop 是一个联合体, Rust 不会为联合体自动实现 Drop. 因为联合体是所有的字段共用内存, 不能随便被析构, 否则会引起未定义行为.
Rust 1.48.0 版本下的源码
已不再是联合体定义
The text was updated successfully, but these errors were encountered: