@@ -13,6 +13,8 @@ use crate::sys::sync as sys;
13
13
/// For more information about mutexes, check out the documentation for the poisoning variant of
14
14
/// this lock (which can be found at [`poison::Mutex`]).
15
15
///
16
+ /// [`poison::Mutex`]: crate::sync::poison::Mutex
17
+ ///
16
18
/// # Examples
17
19
///
18
20
/// ```
@@ -143,8 +145,6 @@ use crate::sys::sync as sys;
143
145
///
144
146
/// assert_eq!(*res_mutex.lock(), 800);
145
147
/// ```
146
- ///
147
- /// [`poison::Mutex`]: crate::sync::poison::Mutex
148
148
#[ unstable( feature = "nonpoison_mutex" , issue = "134645" ) ]
149
149
#[ cfg_attr( not( test) , rustc_diagnostic_item = "NonPoisonMutex" ) ]
150
150
pub struct Mutex < T : ?Sized > {
@@ -226,11 +226,11 @@ unsafe impl<T: ?Sized + Sync> Sync for MutexGuard<'_, T> {}
226
226
/// The data protected by the mutex can be accessed through this guard via its
227
227
/// [`Deref`] and [`DerefMut`] implementations.
228
228
///
229
- /// This structure is created by the [`map`] and [`try_map `] methods on
229
+ /// This structure is created by the [`map`] and [`filter_map `] methods on
230
230
/// [`MutexGuard`].
231
231
///
232
232
/// [`map`]: MutexGuard::map
233
- /// [`try_map `]: MutexGuard::try_map
233
+ /// [`filter_map `]: MutexGuard::filter_map
234
234
/// [`Condvar`]: crate::sync::Condvar
235
235
#[ must_use = "if unused the Mutex will immediately unlock" ]
236
236
#[ must_not_suspend = "holding a MappedMutexGuard across suspend \
@@ -382,23 +382,20 @@ impl<T: ?Sized> Mutex<T> {
382
382
383
383
/// Attempts to acquire this lock.
384
384
///
385
- /// If the lock could not be acquired at this time, then [`None`] is returned.
386
- /// Otherwise, an RAII guard is returned. The lock will be unlocked when the
387
- /// guard is dropped.
385
+ /// This function does not block. If the lock could not be acquired at this time, then
386
+ /// [`WouldBlock`] is returned. Otherwise, an RAII guard is returned.
388
387
///
389
- /// This function does not block .
388
+ /// The lock will be unlocked when the guard is dropped .
390
389
///
391
390
/// # Errors
392
391
///
393
- /// If the mutex could not be acquired because it is already locked, then
394
- /// this call will return [`None`] .
392
+ /// If the mutex could not be acquired because it is already locked, then this call will return
393
+ /// the [`WouldBlock`] error .
395
394
///
396
395
/// # Examples
397
396
///
398
397
/// ```
399
- /// #![feature(nonpoison_mutex)]
400
- ///
401
- /// use std::sync::{Arc, nonpoison::Mutex};
398
+ /// use std::sync::{Arc, Mutex};
402
399
/// use std::thread;
403
400
///
404
401
/// let mutex = Arc::new(Mutex::new(0));
@@ -412,7 +409,7 @@ impl<T: ?Sized> Mutex<T> {
412
409
/// println!("try_lock failed");
413
410
/// }
414
411
/// }).join().expect("thread::spawn failed");
415
- /// assert_eq!(*mutex.lock(), 10);
412
+ /// assert_eq!(*mutex.lock().unwrap() , 10);
416
413
/// ```
417
414
#[ unstable( feature = "nonpoison_mutex" , issue = "134645" ) ]
418
415
pub fn try_lock ( & self ) -> TryLockResult < MutexGuard < ' _ , T > > {
@@ -567,7 +564,7 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> {
567
564
U : ?Sized ,
568
565
{
569
566
// SAFETY: the conditions of `MutexGuard::new` were satisfied when the original guard
570
- // was created, and have been upheld throughout `map` and/or `try_map `.
567
+ // was created, and have been upheld throughout `map` and/or `filter_map `.
571
568
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
572
569
// passed to it. If the closure panics, the guard will be dropped.
573
570
let data = NonNull :: from ( f ( unsafe { & mut * orig. lock . data . get ( ) } ) ) ;
@@ -582,17 +579,16 @@ impl<'a, T: ?Sized> MutexGuard<'a, T> {
582
579
/// The `Mutex` is already locked, so this cannot fail.
583
580
///
584
581
/// This is an associated function that needs to be used as
585
- /// `MutexGuard::try_map (...)`. A method would interfere with methods of the
582
+ /// `MutexGuard::filter_map (...)`. A method would interfere with methods of the
586
583
/// same name on the contents of the `MutexGuard` used through `Deref`.
587
- #[ doc( alias = "filter_map" ) ]
588
584
#[ unstable( feature = "mapped_lock_guards" , issue = "117108" ) ]
589
- pub fn try_map < U , F > ( orig : Self , f : F ) -> Result < MappedMutexGuard < ' a , U > , Self >
585
+ pub fn filter_map < U , F > ( orig : Self , f : F ) -> Result < MappedMutexGuard < ' a , U > , Self >
590
586
where
591
587
F : FnOnce ( & mut T ) -> Option < & mut U > ,
592
588
U : ?Sized ,
593
589
{
594
590
// SAFETY: the conditions of `MutexGuard::new` were satisfied when the original guard
595
- // was created, and have been upheld throughout `map` and/or `try_map `.
591
+ // was created, and have been upheld throughout `map` and/or `filter_map `.
596
592
// The signature of the closure guarantees that it will not "leak" the lifetime of the reference
597
593
// passed to it. If the closure panics, the guard will be dropped.
598
594
match f ( unsafe { & mut * orig. lock . data . get ( ) } ) {
0 commit comments