Add From impls for wrapper types by Jules-Bertholet · Pull Request #146013 · rust-lang/rust (original) (raw)

These are for consistency with the existing From<T> impls for Box<T>, Rc<T>, Arc<T>, Option<T>, Poll<T>, Cell<T>, UnsafeCell<T>, SyncUnsafeCell<T>, OnceCell<T>, RefCell<T>, UnsafePinned<T>, Exclusive<T>, Mutex<T>, OnceLock<T>, ReentrantLock<T>, and RwLock<T>. Also, they are useful for convenience: value.into() is shorter than WrapperType::new(value).

The Copy bound on the ManuallyDrop impl is to ensure users can’t accidentally leak data with an into(), and to ensure the conversion is “value-preserving” as From’s docs require (Copy implies a trivial destructor). The UnwindSafe bound on the AssertUnwindSafe impl has an analogous motivation.