pub struct UniqueArc<T, A = Global>{ /* private fields */ }unique_rc_arc)Expand description
A uniquely owned Arc.
This represents an Arc that is known to be uniquely owned – that is, have exactly one strong
reference. Multiple weak pointers can be created, but attempts to upgrade those to strong
references will fail unless the UniqueArc they point to has been converted into a regular Arc.
Because it is uniquely owned, the contents of a UniqueArc can be freely mutated. A common
use case is to have an object be mutable during its initialization phase but then have it become
immutable and converted to a normal Arc.
This can be used as a flexible way to create cyclic data structures, as in the example below.
#![feature(unique_rc_arc)]
use std::sync::{Arc, Weak, UniqueArc};
struct Gadget {
me: Weak<Gadget>,
}
fn create_gadget() -> Option<Arc<Gadget>> {
let mut rc = UniqueArc::new(Gadget {
me: Weak::new(),
});
rc.me = UniqueArc::downgrade(&rc);
Some(UniqueArc::into_arc(rc))
}
create_gadget().unwrap();An advantage of using UniqueArc over Arc::new_cyclic to build cyclic data structures is that
Arc::new_cyclic’s data_fn parameter cannot be async or return a Result. As shown in the
previous example, UniqueArc allows for more flexibility in the construction of cyclic data,
including fallible or async constructors.
Implementations§
Source§impl<T> UniqueArc<T>
impl<T> UniqueArc<T>
Sourcepub fn new(value: T) -> UniqueArc<T>
🔬This is a nightly-only experimental API. (unique_rc_arc)
pub fn new(value: T) -> UniqueArc<T>
unique_rc_arc)Creates a new UniqueArc.
Weak references to this UniqueArc can be created with UniqueArc::downgrade. Upgrading
these weak references will fail before the UniqueArc has been converted into an Arc.
After converting the UniqueArc into an Arc, any weak references created beforehand will
point to the new Arc.
Source§impl<T, A> UniqueArc<T, A>where
A: Allocator,
impl<T, A> UniqueArc<T, A>where
A: Allocator,
Sourcepub fn new_in(data: T, alloc: A) -> UniqueArc<T, A>
🔬This is a nightly-only experimental API. (unique_rc_arc)
pub fn new_in(data: T, alloc: A) -> UniqueArc<T, A>
unique_rc_arc)Creates a new UniqueArc in the provided allocator.
Weak references to this UniqueArc can be created with UniqueArc::downgrade. Upgrading
these weak references will fail before the UniqueArc has been converted into an Arc.
After converting the UniqueArc into an Arc, any weak references created beforehand will
point to the new Arc.
Source§impl<T, A> UniqueArc<T, A>
impl<T, A> UniqueArc<T, A>
Trait Implementations§
Source§impl<T, A> BorrowMut<T> for UniqueArc<T, A>
impl<T, A> BorrowMut<T> for UniqueArc<T, A>
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, A> Ord for UniqueArc<T, A>
impl<T, A> Ord for UniqueArc<T, A>
Source§fn cmp(&self, other: &UniqueArc<T, A>) -> Ordering
fn cmp(&self, other: &UniqueArc<T, A>) -> Ordering
Comparison for two UniqueArcs.
The two are compared by calling cmp() on their inner values.
§Examples
#![feature(unique_rc_arc)]
use std::sync::UniqueArc;
use std::cmp::Ordering;
let five = UniqueArc::new(5);
assert_eq!(Ordering::Less, five.cmp(&UniqueArc::new(6)));1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<T, A> PartialEq for UniqueArc<T, A>
impl<T, A> PartialEq for UniqueArc<T, A>
Source§impl<T, A> PartialOrd for UniqueArc<T, A>
impl<T, A> PartialOrd for UniqueArc<T, A>
Source§fn partial_cmp(&self, other: &UniqueArc<T, A>) -> Option<Ordering>
fn partial_cmp(&self, other: &UniqueArc<T, A>) -> Option<Ordering>
Partial comparison for two UniqueArcs.
The two are compared by calling partial_cmp() on their inner values.
§Examples
#![feature(unique_rc_arc)]
use std::sync::UniqueArc;
use std::cmp::Ordering;
let five = UniqueArc::new(5);
assert_eq!(Some(Ordering::Less), five.partial_cmp(&UniqueArc::new(6)));Source§fn lt(&self, other: &UniqueArc<T, A>) -> bool
fn lt(&self, other: &UniqueArc<T, A>) -> bool
Less-than comparison for two UniqueArcs.
The two are compared by calling < on their inner values.
§Examples
#![feature(unique_rc_arc)]
use std::sync::UniqueArc;
let five = UniqueArc::new(5);
assert!(five < UniqueArc::new(6));Source§fn le(&self, other: &UniqueArc<T, A>) -> bool
fn le(&self, other: &UniqueArc<T, A>) -> bool
‘Less than or equal to’ comparison for two UniqueArcs.
The two are compared by calling <= on their inner values.
§Examples
#![feature(unique_rc_arc)]
use std::sync::UniqueArc;
let five = UniqueArc::new(5);
assert!(five <= UniqueArc::new(5));Source§fn gt(&self, other: &UniqueArc<T, A>) -> bool
fn gt(&self, other: &UniqueArc<T, A>) -> bool
Greater-than comparison for two UniqueArcs.
The two are compared by calling > on their inner values.
§Examples
#![feature(unique_rc_arc)]
use std::sync::UniqueArc;
let five = UniqueArc::new(5);
assert!(five > UniqueArc::new(4));Source§fn ge(&self, other: &UniqueArc<T, A>) -> bool
fn ge(&self, other: &UniqueArc<T, A>) -> bool
‘Greater than or equal to’ comparison for two UniqueArcs.
The two are compared by calling >= on their inner values.
§Examples
#![feature(unique_rc_arc)]
use std::sync::UniqueArc;
let five = UniqueArc::new(5);
assert!(five >= UniqueArc::new(5));impl<T, U, A> CoerceUnsized<UniqueArc<U, A>> for UniqueArc<T, A>
impl<T, A> DerefPure for UniqueArc<T, A>
impl<T, U> DispatchFromDyn<UniqueArc<U>> for UniqueArc<T>
impl<T, A> Eq for UniqueArc<T, A>
impl<T> PinCoerceUnsized for UniqueArc<T>where
T: ?Sized,
impl<T, A> Send for UniqueArc<T, A>
impl<T, A> Sync for UniqueArc<T, A>
impl<T, A> Unpin for UniqueArc<T, A>
Auto Trait Implementations§
impl<T, A> Freeze for UniqueArc<T, A>
impl<T, A> RefUnwindSafe for UniqueArc<T, A>
impl<T, A> UnwindSafe for UniqueArc<T, A>
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<T> CustomError for T
impl<T> CustomError for T
Source§impl<T, A> DynAccess<T> for A
impl<T, A> DynAccess<T> for A
Source§fn load(&self) -> DynGuard<T>
fn load(&self) -> DynGuard<T>
Access::load.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
Source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();Source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
Source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
Source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
Source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
Source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
Source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
Source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();Source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
Source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
Source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
Source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();Source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi Quirk value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();Source§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.Source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);Source§impl<T> Source for T
impl<T> Source for T
Source§type Slice<'a> = <<T as Deref>::Target as Source>::Slice<'a>
where
T: 'a
type Slice<'a> = <<T as Deref>::Target as Source>::Slice<'a> where T: 'a
Source can be sliced into.Source§fn read<'a, Chunk>(&'a self, offset: usize) -> Option<Chunk>where
Chunk: Chunk<'a>,
fn read<'a, Chunk>(&'a self, offset: usize) -> Option<Chunk>where
Chunk: Chunk<'a>,
None when reading
out of bounds would occur. Read moreSource§unsafe fn read_byte_unchecked(&self, offset: usize) -> u8
unsafe fn read_byte_unchecked(&self, offset: usize) -> u8
Source§fn slice(&self, range: Range<usize>) -> Option<<T as Source>::Slice<'_>>
fn slice(&self, range: Range<usize>) -> Option<<T as Source>::Slice<'_>>
slice::get(range). Read moreSource§unsafe fn slice_unchecked(
&self,
range: Range<usize>,
) -> <T as Source>::Slice<'_>
unsafe fn slice_unchecked( &self, range: Range<usize>, ) -> <T as Source>::Slice<'_>
slice::get_unchecked(range). Read moreSource§fn is_boundary(&self, index: usize) -> bool
fn is_boundary(&self, index: usize) -> bool
Source§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Lower case
letters are used (e.g. f9b4ca)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self into the result. Upper case
letters are used (e.g. F9B4CA)