跳到主要内容

MutexGuard

结构体 MutexGuard 

1.0.0 · Source
pub struct MutexGuard<'a, T>
where T: 'a + ?Sized,
{ /* private fields */ }
展开描述

An RAII implementation of 一个 “scoped lock” of 一个 mutex. When this structure is dropped (falls out of scope), the lock , unlocked.

此 data protected by the mutex can be accessed through this guard via its DerefDerefMut implementations.

This structure is created by the locktry_lock methods on Mutex

实现§

Source§

impl<'a, T> MutexGuard<'a, T>
where T: ?Sized,

Source

pub fn map<U, F>(orig: MutexGuard<'a, T>, f: F) -> MappedMutexGuard<'a, U>
where F: FnOnce(&mut T) -> &mut U, U: ?Sized,

🔬This is a nightly-only experimental API. (mapped_lock_guards)

Makes 一个 MappedMutexGuard 用于 一个 component of the borrowed data, e.g. an enum variant.

Mutex is already locked, so this cannot fail.

This 是 associated function that needs 到 be 用 as MutexGuard::map(。。。)。 A method would interfere with methods of the same name on the contents of the MutexGuard 用 through Deref

Source

pub fn filter_map<U, F>( orig: MutexGuard<'a, T>, f: F, ) -> Result<MappedMutexGuard<'a, U>, MutexGuard<'a, T>>
where F: FnOnce(&mut T) -> Option<&mut U>, U: ?Sized,

🔬This is a nightly-only experimental API. (mapped_lock_guards)

Makes 一个 MappedMutexGuard 用于 一个 component of the borrowed data. 此 original guard is returned as an Err(。。。) if the closure returns None

Mutex is already locked, so this cannot fail.

This 是 associated function that needs 到 be 用 as MutexGuard::filter_map(。。。)。 A method would interfere with methods of the same name on the contents of the MutexGuard 用 through Deref

Trait 实现§

1.16.0 · Source§

impl<T> Debug for MutexGuard<'_, T>
where T: Debug + ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

使用给定的格式化器格式化此值。 更多信息
1.0.0 · Source§

impl<T> Deref for MutexGuard<'_, T>
where T: ?Sized,

Source§

type Target = T

解引用后得到的类型。
Source§

fn deref(&self) -> &T

解引用此值。
1.0.0 · Source§

impl<T> DerefMut for MutexGuard<'_, T>
where T: ?Sized,

Source§

fn deref_mut(&mut self) -> &mut T

以可变方式解引用此值。
1.20.0 · Source§

impl<T> Display for MutexGuard<'_, T>
where T: Display + ?Sized,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

使用给定的格式化器格式化此值。 更多信息
1.0.0 · Source§

impl<T> Drop for MutexGuard<'_, T>
where T: ?Sized,

Source§

fn drop(&mut self)

执行此类型的析构函数。 更多信息
1.0.0 · Source§

impl<T> !Send for MutexGuard<'_, T>
where T: ?Sized,

A MutexGuard is not Send 到 maximize platform portability.

On platforms that use POSIX threads (commonly referred 到 as pthreads) there 是 requirement 到 release mutex locks on the same thread they were acquired. For this reason, MutexGuard must not implement Send 到 prevent it being dropped 从 another thread.

1.19.0 · Source§

impl<T> Sync for MutexGuard<'_, T>
where T: Sync + ?Sized,

T must be Sync 用于 一个 MutexGuard<T> 到 be Sync because it is possible 到 get 一个 &T&MutexGuard (via Deref)。

自动 Trait 实现§

§

impl<'a, T> Freeze for MutexGuard<'a, T>
where T: ?Sized,

§

impl<'a, T> RefUnwindSafe for MutexGuard<'a, T>
where T: ?Sized,

§

impl<'a, T> Unpin for MutexGuard<'a, T>
where T: ?Sized,

§

impl<'a, T> UnsafeUnpin for MutexGuard<'a, T>
where T: ?Sized,

§

impl<'a, T> UnwindSafe for MutexGuard<'a, T>
where T: ?Sized,

Blanket 实现§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows 从 an owned value. 更多信息
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows 从 an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::从(self)

That is, this conversion is whatever the implementation of From<T> 用于 U 的实现方式。

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
此 target type on which the method may be called.
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value 到 一个 String. 更多信息
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

转换出错时返回的类型。
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。