@@ -6,6 +6,7 @@ use crate::fmt;
6
6
use crate :: mem;
7
7
use crate :: ops:: { Deref , DerefMut } ;
8
8
use crate :: ptr;
9
+ use crate :: sync:: Arc ;
9
10
use crate :: sys_common:: poison:: { self , LockResult , TryLockError , TryLockResult } ;
10
11
use crate :: sys_common:: rwlock as sys;
11
12
@@ -133,6 +134,22 @@ impl<T> RwLock<T> {
133
134
data : UnsafeCell :: new ( t) ,
134
135
}
135
136
}
137
+
138
+ /// Creates a new instance of an `RwLock<T>` which is unlocked, and wraps it in an [`Arc`].
139
+ ///
140
+ /// [`Arc`]: ../../std/sync/struct.Arc.html
141
+ ///
142
+ /// # Examples
143
+ ///
144
+ /// ```
145
+ /// use std::sync::RwLock;
146
+ ///
147
+ /// let lock = RwLock::arc(5);
148
+ /// ```
149
+ #[ unstable( feature = "mutex_arc" , issue = "74866" ) ]
150
+ pub fn arc ( t : T ) -> Arc < RwLock < T > > {
151
+ Arc :: new ( RwLock :: new ( t) )
152
+ }
136
153
}
137
154
138
155
impl < T : ?Sized > RwLock < T > {
@@ -164,7 +181,7 @@ impl<T: ?Sized> RwLock<T> {
164
181
/// use std::sync::{Arc, RwLock};
165
182
/// use std::thread;
166
183
///
167
- /// let lock = Arc::new( RwLock::new(1) );
184
+ /// let lock = RwLock::arc(1 );
168
185
/// let c_lock = Arc::clone(&lock);
169
186
///
170
187
/// let n = lock.read().unwrap();
@@ -320,7 +337,7 @@ impl<T: ?Sized> RwLock<T> {
320
337
/// use std::sync::{Arc, RwLock};
321
338
/// use std::thread;
322
339
///
323
- /// let lock = Arc::new( RwLock::new(0) );
340
+ /// let lock = RwLock::arc(0 );
324
341
/// let c_lock = Arc::clone(&lock);
325
342
///
326
343
/// let _ = thread::spawn(move || {
0 commit comments