Trait FragileMutContainer

Source
pub trait FragileMutContainer<T: ?Sized>: FragileTryMutContainer<T> + FragileContainer<T> {
    // Required method
    fn get_mut(&mut self) -> Self::RefMut<'_>;
}
Expand description

An abstraction over some container which owns a T and can infallibly provide mutable or immutable references to it, or attempt to be consumed to return the inner T (if T is Sized).

§Fragility: Potential Panics or Deadlocks

This container should be assumed to be fragile, unless it is known to implement MutContainer<T>.

§None values

Note that into_inner is still permitted to return None, even though get_ref and get_mut do not fail, and most implementors should make try_get_ref and try_get_mut infallible as well. A container should clearly document when into_inner returns None.

Required Methods§

Source

fn get_mut(&mut self) -> Self::RefMut<'_>

Mutably borrow the inner T.

§Fragility: Potential Panics or Deadlocks

Unless this FragileMutContainer is also a MutContainer, implementations are permitted to panic or deadlock if this method is called from a thread which already has a reference to the inner T of this container.

Read more about fragility.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: ?Sized> FragileMutContainer<T> for Box<T>

Source§

fn get_mut(&mut self) -> Self::RefMut<'_>

Infallibly get mutable access to the inner T.

Source§

impl<T: ?Sized> FragileMutContainer<T> for Rc<RefCell<T>>

Source§

fn get_mut(&mut self) -> Self::RefMut<'_>

Get mutable access to the inner T.

Uses RefCell::borrow_mut, so this container is fragile.

§Panics

Panics if the contract of a fragile container is broken.

Source§

impl<T: ?Sized> FragileMutContainer<T> for Arc<Mutex<T>>

Source§

fn get_mut(&mut self) -> Self::RefMut<'_>

Get mutable access to the inner T.

Uses Mutex::lock, so this container is fragile.

§Panics and Deadlocks

Panics if a poison error is encountered, which can only occur if another thread has already panicked.

May also panic or deadlock if the contract of a fragile container is broken.

Source§

impl<T: ?Sized> FragileMutContainer<T> for Arc<RwLock<T>>

Source§

fn get_mut(&mut self) -> Self::RefMut<'_>

Get mutable access to the inner T.

Uses RwLock::write, so this container is fragile.

§Panics and Deadlocks

Panics if a poison error is encountered, which can only occur if another thread has already panicked.

May also panic or deadlock if the contract of a fragile container is broken.

Implementors§