Trait FragileContainer

Source
pub trait FragileContainer<T: ?Sized>: FragileTryContainer<T> {
    // Required method
    fn get_ref(&self) -> Self::Ref<'_>;
}
Expand description

An abstraction over some container which owns a T and can infallibly provide 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 Container<T>.

§None values

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

Required Methods§

Source

fn get_ref(&self) -> Self::Ref<'_>

Immutably borrow the inner T.

§Fragility: Potential Panics or Deadlocks

Unless this FragileContainer is also a Container, 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> FragileContainer<T> for Box<T>

Source§

fn get_ref(&self) -> Self::Ref<'_>

Infallibly get immutable access to the inner T.

Source§

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

Source§

fn get_ref(&self) -> Self::Ref<'_>

Get immutable access to the inner T.

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

§Panics

Panics if the contract of a fragile container is broken.

Source§

impl<T: ?Sized> FragileContainer<T> for Rc<T>

Source§

fn get_ref(&self) -> Self::Ref<'_>

Infallibly get immutable access to the inner T.

Source§

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

Source§

fn get_ref(&self) -> Self::Ref<'_>

Get immutable 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> FragileContainer<T> for Arc<RwLock<T>>

Source§

fn get_ref(&self) -> Self::Ref<'_>

Get immutable access to the inner T.

Uses RwLock::read, 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> FragileContainer<T> for Arc<T>

Source§

fn get_ref(&self) -> Self::Ref<'_>

Infallibly get immutable access to the inner T.

Implementors§

Source§

impl<T: ?Sized> FragileContainer<T> for T