Movatterモバイル変換


[0]ホーム

URL:


UniqueArc

std::sync

StructUniqueArc 

Source
pub struct UniqueArc<T, A =Global>
where A:Allocator, T: ?Sized,
{/* private fields */ }
🔬This is a nightly-only experimental API. (unique_rc_arc #112566)
Expand description

A uniquely ownedArc.

This represents anArc that is known to be uniquely owned – that is, have exactly one strongreference. Multiple weak pointers can be created, but attempts to upgrade those to strongreferences will fail unless theUniqueArc they point to has been converted into a regularArc.

Because it is uniquely owned, the contents of aUniqueArc can be freely mutated. A commonuse case is to have an object be mutable during its initialization phase but then have it becomeimmutable and converted to a normalArc.

This can be used as a flexible way to create cyclic data structures, as in the example below.

#![feature(unique_rc_arc)]usestd::sync::{Arc, Weak, UniqueArc};structGadget {    me: Weak<Gadget>,}fncreate_gadget() ->Option<Arc<Gadget>> {letmutrc = UniqueArc::new(Gadget {        me: Weak::new(),    });    rc.me = UniqueArc::downgrade(&rc);Some(UniqueArc::into_arc(rc))}create_gadget().unwrap();

An advantage of usingUniqueArc overArc::new_cyclic to build cyclic data structures is thatArc::new_cyclic’sdata_fn parameter cannot be async or return aResult. As shown in theprevious example,UniqueArc allows for more flexibility in the construction of cyclic data,including fallible or async constructors.

Implementations§

Source§

impl<T>UniqueArc<T>

Source

pub fnnew(value: T) ->UniqueArc<T>

🔬This is a nightly-only experimental API. (unique_rc_arc #112566)

Creates a newUniqueArc.

Weak references to thisUniqueArc can be created withUniqueArc::downgrade. Upgradingthese weak references will fail before theUniqueArc has been converted into anArc.After converting theUniqueArc into anArc, any weak references created beforehand willpoint to the newArc.

Source

pub fnmap<U>(this:UniqueArc<T>, f: implFnOnce(T) -> U) ->UniqueArc<U>

🔬This is a nightly-only experimental API. (smart_pointer_try_map #144419)

Maps the value in aUniqueArc, reusing the allocation if possible.

f is called on a reference to the value in theUniqueArc, and the result is returned,also in aUniqueArc.

Note: this is an associated function, which means that you haveto call it asUniqueArc::map(u, f) instead ofu.map(f). Thisis so that there is no conflict with a method on the inner type.

§Examples
#![feature(smart_pointer_try_map)]#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letr = UniqueArc::new(7);letnew = UniqueArc::map(r, |i| i +7);assert_eq!(*new,14);
Source

pub fntry_map<R>( this:UniqueArc<T>, f: implFnOnce(T) -> R,) -> <<R asTry>::Residual asResidual<UniqueArc<<R asTry>::Output>>>::TryType
where R:Try, <R asTry>::Residual:Residual<UniqueArc<<R asTry>::Output>>,

🔬This is a nightly-only experimental API. (smart_pointer_try_map #144419)

Attempts to map the value in aUniqueArc, reusing the allocation if possible.

f is called on a reference to the value in theUniqueArc, and if the operation succeeds,the result is returned, also in aUniqueArc.

Note: this is an associated function, which means that you haveto call it asUniqueArc::try_map(u, f) instead ofu.try_map(f). Thisis so that there is no conflict with a method on the inner type.

§Examples
#![feature(smart_pointer_try_map)]#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letb = UniqueArc::new(7);letnew = UniqueArc::try_map(b, u32::try_from).unwrap();assert_eq!(*new,7);
Source§

impl<T, A>UniqueArc<T, A>
where A:Allocator,

Source

pub fnnew_in(data: T, alloc: A) ->UniqueArc<T, A>

🔬This is a nightly-only experimental API. (unique_rc_arc #112566)

Creates a newUniqueArc in the provided allocator.

Weak references to thisUniqueArc can be created withUniqueArc::downgrade. Upgradingthese weak references will fail before theUniqueArc has been converted into anArc.After converting theUniqueArc into anArc, any weak references created beforehand willpoint to the newArc.

Source§

impl<T, A>UniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source

pub fninto_arc(this:UniqueArc<T, A>) ->Arc<T, A>

🔬This is a nightly-only experimental API. (unique_rc_arc #112566)

Converts theUniqueArc into a regularArc.

This consumes theUniqueArc and returns a regularArc that contains thevalue thatis passed tointo_arc.

Any weak references created before this method is called can now be upgraded to strongreferences.

Source§

impl<T, A>UniqueArc<T, A>
where A:Allocator +Clone, T: ?Sized,

Source

pub fndowngrade(this: &UniqueArc<T, A>) ->Weak<T, A>

🔬This is a nightly-only experimental API. (unique_rc_arc #112566)

Creates a new weak reference to theUniqueArc.

Attempting to upgrade this weak reference will fail before theUniqueArc has been convertedto aArc usingUniqueArc::into_arc.

Trait Implementations§

Source§

impl<T, A>AsMut<T> forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fnas_mut(&mut self) ->&mut T

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

impl<T, A>AsRef<T> forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fnas_ref(&self) ->&T

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

impl<T, A>Borrow<T> forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

impl<T, A>BorrowMut<T> forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T, A>Debug forUniqueArc<T, A>
where T:Debug + ?Sized, A:Allocator,

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>

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

impl<T, A>Deref forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

typeTarget = T

The resulting type after dereferencing.
Source§

fnderef(&self) ->&T

Dereferences the value.
Source§

impl<T, A>DerefMut forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fnderef_mut(&mut self) ->&mut T

Mutably dereferences the value.
Source§

impl<T, A>Display forUniqueArc<T, A>
where T:Display + ?Sized, A:Allocator,

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>

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

impl<T, A>Drop forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fndrop(&mut self)

Executes the destructor for this type.Read more
Source§

impl<T, A>Hash forUniqueArc<T, A>
where T:Hash + ?Sized, A:Allocator,

Source§

fnhash<H>(&self, state:&mut H)
where H:Hasher,

Feeds this value into the givenHasher.Read more
1.3.0 ·Source§

fnhash_slice<H>(data: &[Self], state:&mut H)
where H:Hasher, Self:Sized,

Feeds a slice of this type into the givenHasher.Read more
Source§

impl<T, A>Ord forUniqueArc<T, A>
where T:Ord + ?Sized, A:Allocator,

Source§

fncmp(&self, other: &UniqueArc<T, A>) ->Ordering

Comparison for twoUniqueArcs.

The two are compared by callingcmp() on their inner values.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;usestd::cmp::Ordering;letfive = UniqueArc::new(5);assert_eq!(Ordering::Less, five.cmp(&UniqueArc::new(6)));
1.21.0 ·Source§

fnmax(self, other: Self) -> Self
where Self:Sized,

Compares and returns the maximum of two values.Read more
1.21.0 ·Source§

fnmin(self, other: Self) -> Self
where Self:Sized,

Compares and returns the minimum of two values.Read more
1.50.0 ·Source§

fnclamp(self, min: Self, max: Self) -> Self
where Self:Sized,

Restrict a value to a certain interval.Read more
Source§

impl<T, A>PartialEq forUniqueArc<T, A>
where T:PartialEq + ?Sized, A:Allocator,

Source§

fneq(&self, other: &UniqueArc<T, A>) ->bool

Equality for twoUniqueArcs.

TwoUniqueArcs are equal if their inner values are equal.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letfive = UniqueArc::new(5);assert!(five == UniqueArc::new(5));
1.0.0 ·Source§

fnne(&self, other:&Rhs) ->bool

Tests for!=. The default implementation is almost always sufficient,and should not be overridden without very good reason.
Source§

impl<T, A>PartialOrd forUniqueArc<T, A>
where T:PartialOrd + ?Sized, A:Allocator,

Source§

fnpartial_cmp(&self, other: &UniqueArc<T, A>) ->Option<Ordering>

Partial comparison for twoUniqueArcs.

The two are compared by callingpartial_cmp() on their inner values.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;usestd::cmp::Ordering;letfive = UniqueArc::new(5);assert_eq!(Some(Ordering::Less), five.partial_cmp(&UniqueArc::new(6)));
Source§

fnlt(&self, other: &UniqueArc<T, A>) ->bool

Less-than comparison for twoUniqueArcs.

The two are compared by calling< on their inner values.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letfive = UniqueArc::new(5);assert!(five < UniqueArc::new(6));
Source§

fnle(&self, other: &UniqueArc<T, A>) ->bool

‘Less than or equal to’ comparison for twoUniqueArcs.

The two are compared by calling<= on their inner values.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letfive = UniqueArc::new(5);assert!(five <= UniqueArc::new(5));
Source§

fngt(&self, other: &UniqueArc<T, A>) ->bool

Greater-than comparison for twoUniqueArcs.

The two are compared by calling> on their inner values.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letfive = UniqueArc::new(5);assert!(five > UniqueArc::new(4));
Source§

fnge(&self, other: &UniqueArc<T, A>) ->bool

‘Greater than or equal to’ comparison for twoUniqueArcs.

The two are compared by calling>= on their inner values.

§Examples
#![feature(unique_rc_arc)]usestd::sync::UniqueArc;letfive = UniqueArc::new(5);assert!(five >= UniqueArc::new(5));
Source§

impl<T, A>Pointer forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>

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

impl<T, U, A>CoerceUnsized<UniqueArc<U, A>> forUniqueArc<T, A>
where T:Unsize<U> + ?Sized, A:Allocator, U: ?Sized,

Source§

impl<T, A>DerefPure forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Source§

impl<T, U>DispatchFromDyn<UniqueArc<U>> forUniqueArc<T>
where T:Unsize<U> + ?Sized, U: ?Sized,

Source§

impl<T, A>Eq forUniqueArc<T, A>
where T:Eq + ?Sized, A:Allocator,

Source§

impl<T>PinCoerceUnsized forUniqueArc<T>
where T: ?Sized,

Source§

impl<T, A>Send forUniqueArc<T, A>
where T:Sync +Send + ?Sized, A:Allocator +Send,

Source§

impl<T, A>Sync forUniqueArc<T, A>
where T:Sync +Send + ?Sized, A:Allocator +Sync,

Source§

impl<T, A>Unpin forUniqueArc<T, A>
where A:Allocator, T: ?Sized,

Auto Trait Implementations§

§

impl<T, A>Freeze forUniqueArc<T, A>
where A:Freeze, T: ?Sized,

§

impl<T, A>RefUnwindSafe forUniqueArc<T, A>

§

impl<T, A>UnwindSafe forUniqueArc<T, A>

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

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

Source§

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

Source§

typeTarget = T

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

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

Source§

fnto_string(&self) ->String

Converts the given value to aString.Read more
Source§

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

Source§

typeError =Infallible

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

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

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

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2026 Movatter.jp