From 1bfc6c1296c0b174577d6817557d0d1ed77687fb Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Sat, 18 Nov 2017 16:49:04 +0000 Subject: [PATCH 1/2] impl From for Mutex --- src/libstd/sync/mutex.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index eb507858b92b2..81f5594bc5231 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -382,6 +382,17 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for Mutex { } } +#[stable(feature = "mutex_from", since = "1.22.0")] +impl From for Mutex { + /// Creates a new mutex in an unlocked state ready for use. + /// This is equivalent to [`Mutex::new`]. + /// + /// [`Mutex::new`]: #method.new + fn from(t: T) -> Self { + Mutex::new(t) + } +} + #[stable(feature = "mutex_default", since = "1.10.0")] impl Default for Mutex { /// Creates a `Mutex`, with the `Default` value for T. From 0855ea18324f06896818c7df920a5091aa931ff6 Mon Sep 17 00:00:00 2001 From: Eduardo Pinho Date: Sat, 18 Nov 2017 21:05:06 +0000 Subject: [PATCH 2/2] impl From for RwLock --- src/libstd/sync/rwlock.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 6216d78528dbb..fd6cff6b69c40 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -457,6 +457,17 @@ impl Default for RwLock { } } +#[stable(feature = "rw_lock_from", since = "1.22.0")] +impl From for RwLock { + /// Creates a new instance of an `RwLock` which is unlocked. + /// This is equivalent to [`RwLock::new`]. + /// + /// [`RwLock::new`]: #method.new + fn from(t: T) -> Self { + RwLock::new(t) + } +} + impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> { unsafe fn new(lock: &'rwlock RwLock) -> LockResult> {