Struct ArcContainer

Source
pub struct ArcContainer<T>(/* private fields */);
Available on crate feature alloc only.
Expand description

Container implementation via privately implemented Arc

§Example

let mut container = ArcContainer::init_value((), 42);

let shared: &i32 = &container;
let exclusive: Pin<&mut i32> = container.try_inner().expect("Single Arc should have exclusive access");
let mut container2 = container.try_mv::<ArcContainer<_>>(()).expect("Single Arc should be always successfully moved out of");

let container3 = container2.clone(); // container is not longer exclusive

assert!(container2.try_inner().is_none(), "Non-excluive Arc should not be able to get &mut");
let shared: &i32 = &container2; // shared reference is still ok
assert!(container2.try_mv::<ArcContainer<_>>(()).is_none());

Implementations§

Source§

impl<T> ArcContainer<T>

Source

pub fn iter<'r0>(&'r0 self) -> <&'r0 Self as IntoIterator>::IntoIter
where for<'r1> &'r1 T: IntoIterator,

Same as <&Self as IntoIterator>::into_iter(self)

Trait Implementations§

Source§

impl<T> AsRef<<ArcContainer<T> as Container>::Inner> for ArcContainer<T>

Source§

fn as_ref(&self) -> &<ArcContainer<T> as Container>::Inner

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Clone for ArcContainer<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

const fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Container for ArcContainer<T>

Source§

type Allocator = ()

Type used to create uninitialized version of the container Read more
Source§

type Inner = T

Contained type
Source§

type Uninit = UninitArcContainer<T>

Container in the uninitialized state. Usually somewhat similar to container itself Read more
Source§

fn uninit(_allocator: ()) -> Self::Uninit

Creates container in the uninitialized state Read more
Source§

fn uninit_inner_ptr(uninit: &mut Self::Uninit) -> *mut Self::Inner

Retrieves pointer to the contents of uninit container
Source§

unsafe fn init(uninit: Self::Uninit) -> Self

Safety Read more
Source§

fn try_inner(&mut self) -> Option<Pin<&mut Self::Inner>>

Gets exclusive reference to inner value. Note that exclusive reference is always pinned Read more
Source§

fn try_move_out<O>( self, action: impl FnOnce(*mut Self::Inner) -> O, ) -> Option<O>

Moves value out of the container. action is called at most once (i.e. 1 or 0 times) and provided with a pointer to contained value (i.e. it is valid for reads and points to valid Container::Inner) Read more
Source§

unsafe fn init_ptr( allocator: Self::Allocator, initializer: impl FnOnce(*mut Self::Inner), ) -> Self

Provided helper function creating and initializing the container in a single call Read more
Source§

fn try_mv<C: Container<Inner = Self::Inner>>( self, allocator: C::Allocator, ) -> Option<C>
where Self::Inner: Moveable,

Tries moving value out of the container into a different container Read more
Source§

fn init_value(allocator: Self::Allocator, value: Self::Inner) -> Self

Provided helper function initializing the Container by moving a value into it Read more
Source§

impl<T: Debug> Debug for ArcContainer<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for ArcContainer<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T: Display> Display for ArcContainer<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'r0, T> IntoIterator for &'r0 ArcContainer<T>
where for<'r1> &'r1 T: IntoIterator,

Source§

type Item = <&'r0 T as IntoIterator>::Item

The type of the elements being iterated over.
Source§

type IntoIter = <&'r0 T as IntoIterator>::IntoIter

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ArcContainer<T>

§

impl<T> RefUnwindSafe for ArcContainer<T>
where T: RefUnwindSafe,

§

impl<T> Send for ArcContainer<T>
where T: Send + Sync,

§

impl<T> Sync for ArcContainer<T>
where T: Send + Sync,

§

impl<T> Unpin for ArcContainer<T>

§

impl<T> UnwindSafe for ArcContainer<T>
where T: RefUnwindSafe,

Blanket Implementations§

Source§

impl<S> AddNuclideSpec for S
where S: Deref, <S as Deref>::Target: AddNuclideSpec,

Source§

fn add_nuclide(&self, mixture: Pin<&mut NuclideMixture<'_>>)

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

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

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.