Skip to content

Commit

Permalink
Rollup merge of rust-lang#46082 - Enet4:mutex_from, r=sfackler
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kennytm authored Nov 20, 2017
2 parents e061383 + 0855ea1 commit 2c16502
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/libstd/sync/mutex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
11 changes: 11 additions & 0 deletions src/libstd/sync/rwlock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>> {
Expand Down

0 comments on commit 2c16502

Please sign in to comment.