about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2017-11-21 03:14:41 +0800
committerGitHub <noreply@github.com>2017-11-21 03:14:41 +0800
commit2c16502b929194cd2389c790ca6aec129b5205ad (patch)
tree18735d0f75cf1683493d5f8df6818849a30075dd /src/libstd
parente06138338f78cd2695f857855e685e9e50a2486b (diff)
parent0855ea18324f06896818c7df920a5091aa931ff6 (diff)
downloadrust-2c16502b929194cd2389c790ca6aec129b5205ad.tar.gz
rust-2c16502b929194cd2389c790ca6aec129b5205ad.zip
Rollup merge of #46082 - Enet4:mutex_from, r=sfackler
impl From for Mutex and RwLock

I felt that these implementations were missing, because doing `x.into()` works for other smart containers (such as `RefCell`), and in general I would say that the conversion makes sense.
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/sync/mutex.rs11
-rw-r--r--src/libstd/sync/rwlock.rs11
2 files changed, 22 insertions, 0 deletions
diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs
index eb507858b92..81f5594bc52 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<T> {
     }
 }
 
+#[stable(feature = "mutex_from", since = "1.22.0")]
+impl<T> From<T> for Mutex<T> {
+    /// 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<T: ?Sized + Default> Default for Mutex<T> {
     /// Creates a `Mutex<T>`, with the `Default` value for T.
diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs
index 6216d78528d..fd6cff6b69c 100644
--- a/src/libstd/sync/rwlock.rs
+++ b/src/libstd/sync/rwlock.rs
@@ -457,6 +457,17 @@ impl<T: Default> Default for RwLock<T> {
     }
 }
 
+#[stable(feature = "rw_lock_from", since = "1.22.0")]
+impl<T> From<T> for RwLock<T> {
+    /// Creates a new instance of an `RwLock<T>` 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<T>)
                   -> LockResult<RwLockReadGuard<'rwlock, T>> {