pub struct Arc<T, A =Global>{/* private fields */ }Expand description
A thread-safe reference-counting pointer. ‘Arc’ stands for ‘AtomicallyReference Counted’.
The typeArc<T> provides shared ownership of a value of typeT,allocated in the heap. Invokingclone onArc producesa newArc instance, which points to the same allocation on the heap as thesourceArc, while increasing a reference count. When the lastArcpointer to a given allocation is destroyed, the value stored in that allocation (oftenreferred to as “inner value”) is also dropped.
Shared references in Rust disallow mutation by default, andArc is noexception: you cannot generally obtain a mutable reference to somethinginside anArc. If you do need to mutate through anArc, you have several options:
Use interior mutability with synchronization primitives like
Mutex,RwLock, or one of theAtomictypes.Use clone-on-write semantics with
Arc::make_mutwhich provides efficient mutationwithout requiring interior mutability. This approach clones the data only whenneeded (when there are multiple references) and can be more efficient when mutationsare infrequent.Use
Arc::get_mutwhen you know yourArcis not shared (has a reference count of 1),which provides direct mutable access to the inner value without any cloning.
usestd::sync::Arc;letmutdata = Arc::new(vec![1,2,3]);// This will clone the vector only if there are other references to itArc::make_mut(&mutdata).push(4);assert_eq!(*data,vec![1,2,3,4]);Note: This type is only available on platforms that support atomicloads and stores of pointers, which includes all platforms that supportthestd crate but not all those which only supportalloc.This may be detected at compile time using#[cfg(target_has_atomic = "ptr")].
§Thread Safety
UnlikeRc<T>,Arc<T> uses atomic operations for its referencecounting. This means that it is thread-safe. The disadvantage is thatatomic operations are more expensive than ordinary memory accesses. If youare not sharing reference-counted allocations between threads, consider usingRc<T> for lower overhead.Rc<T> is a safe default, because thecompiler will catch any attempt to send anRc<T> between threads.However, a library might chooseArc<T> in order to give library consumersmore flexibility.
Arc<T> will implementSend andSync as long as theT implementsSend andSync. Why can’t you put a non-thread-safe typeT in anArc<T> to make it thread-safe? This may be a bit counter-intuitive atfirst: after all, isn’t the point ofArc<T> thread safety? The key isthis:Arc<T> makes it thread safe to have multiple ownership of the samedata, but it doesn’t add thread safety to its data. ConsiderArc<RefCell<T>>.RefCell<T> isn’tSync, and ifArc<T> was alwaysSend,Arc<RefCell<T>> would be as well. But then we’d have a problem:RefCell<T> is not thread safe; it keeps track of the borrowing count usingnon-atomic operations.
In the end, this means that you may need to pairArc<T> with some sort ofstd::sync type, usuallyMutex<T>.
§Breaking cycles withWeak
Thedowngrade method can be used to create a non-owningWeak pointer. AWeak pointer can beupgradedto anArc, but this will returnNone if the value stored in the allocation hasalready been dropped. In other words,Weak pointers do not keep the valueinside the allocation alive; however, theydo keep the allocation(the backing store for the value) alive.
A cycle betweenArc pointers will never be deallocated. For this reason,Weak is used to break cycles. For example, a tree could havestrongArc pointers from parent nodes to children, andWeakpointers from children back to their parents.
§Cloning references
Creating a new reference from an existing reference-counted pointer is done using theClone trait implemented forArc<T> andWeak<T>.
usestd::sync::Arc;letfoo = Arc::new(vec![1.0,2.0,3.0]);// The two syntaxes below are equivalent.leta = foo.clone();letb = Arc::clone(&foo);// a, b, and foo are all Arcs that point to the same memory location§Deref behavior
Arc<T> automatically dereferences toT (via theDeref trait),so you can callT’s methods on a value of typeArc<T>. To avoid nameclashes withT’s methods, the methods ofArc<T> itself are associatedfunctions, called usingfully qualified syntax:
Arc<T>’s implementations of traits likeClone may also be called usingfully qualified syntax. Some people prefer to use fully qualified syntax,while others prefer using method-call syntax.
usestd::sync::Arc;letarc = Arc::new(());// Method-call syntaxletarc2 = arc.clone();// Fully qualified syntaxletarc3 = Arc::clone(&arc);Weak<T> does not auto-dereference toT, because the inner value may havealready been dropped.
§Examples
Sharing some immutable data between threads:
usestd::sync::Arc;usestd::thread;letfive = Arc::new(5);for _ in0..10{letfive = Arc::clone(&five); thread::spawn(move|| {println!("{five:?}"); });}Sharing a mutableAtomicUsize:
usestd::sync::Arc;usestd::sync::atomic::{AtomicUsize, Ordering};usestd::thread;letval = Arc::new(AtomicUsize::new(5));for _ in0..10{letval = Arc::clone(&val); thread::spawn(move|| {letv = val.fetch_add(1, Ordering::Relaxed);println!("{v:?}"); });}See therc documentation for more examples of referencecounting in general.
Implementations§
Source§impl<T>Arc<T>
impl<T>Arc<T>
1.60.0 ·Sourcepub fnnew_cyclic<F>(data_fn: F) ->Arc<T>
pub fnnew_cyclic<F>(data_fn: F) ->Arc<T>
Constructs a newArc<T> while giving you aWeak<T> to the allocation,to allow you to construct aT which holds a weak pointer to itself.
Generally, a structure circularly referencing itself, either directly orindirectly, should not hold a strong reference to itself to prevent a memory leak.Using this function, you get access to the weak pointer during theinitialization ofT, before theArc<T> is created, such that you canclone and store it inside theT.
new_cyclic first allocates the managed allocation for theArc<T>,then calls your closure, giving it aWeak<T> to this allocation,and only afterwards completes the construction of theArc<T> by placingtheT returned from your closure into the allocation.
Since the newArc<T> is not fully-constructed untilArc<T>::new_cyclicreturns, callingupgrade on the weak reference inside your closure willfail and result in aNone value.
§Panics
Ifdata_fn panics, the panic is propagated to the caller, and thetemporaryWeak<T> is dropped normally.
§Example
usestd::sync::{Arc, Weak};structGadget { me: Weak<Gadget>,}implGadget {/// Constructs a reference counted Gadget.fnnew() -> Arc<Self> {// `me` is a `Weak<Gadget>` pointing at the new allocation of the // `Arc` we're constructing.Arc::new_cyclic(|me| {// Create the actual struct here.Gadget { me: me.clone() } }) }/// Returns a reference counted pointer to Self.fnme(&self) -> Arc<Self> {self.me.upgrade().unwrap() }}1.82.0 ·Sourcepub fnnew_uninit() ->Arc<MaybeUninit<T>>
pub fnnew_uninit() ->Arc<MaybeUninit<T>>
Constructs a newArc with uninitialized contents.
§Examples
1.92.0 ·Sourcepub fnnew_zeroed() ->Arc<MaybeUninit<T>>
pub fnnew_zeroed() ->Arc<MaybeUninit<T>>
Constructs a newArc with uninitialized contents, with the memorybeing filled with0 bytes.
SeeMaybeUninit::zeroed for examples of correct and incorrect usageof this method.
§Examples
1.33.0 ·Sourcepub fnpin(data: T) ->Pin<Arc<T>>
pub fnpin(data: T) ->Pin<Arc<T>>
Constructs a newPin<Arc<T>>. IfT does not implementUnpin, thendata will be pinned in memory and unable to be moved.
Sourcepub fntry_pin(data: T) ->Result<Pin<Arc<T>>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_pin(data: T) ->Result<Pin<Arc<T>>,AllocError>
allocator_api #32838)Constructs a newPin<Arc<T>>, return an error if allocation fails.
Sourcepub fntry_new(data: T) ->Result<Arc<T>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_new(data: T) ->Result<Arc<T>,AllocError>
allocator_api #32838)Constructs a newArc<T>, returning an error if allocation fails.
§Examples
Sourcepub fntry_new_uninit() ->Result<Arc<MaybeUninit<T>>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_new_uninit() ->Result<Arc<MaybeUninit<T>>,AllocError>
allocator_api #32838)Constructs a newArc with uninitialized contents, returning an errorif allocation fails.
§Examples
Sourcepub fntry_new_zeroed() ->Result<Arc<MaybeUninit<T>>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_new_zeroed() ->Result<Arc<MaybeUninit<T>>,AllocError>
allocator_api #32838)Constructs a newArc with uninitialized contents, with the memorybeing filled with0 bytes, returning an error if allocation fails.
SeeMaybeUninit::zeroed for examples of correct and incorrect usageof this method.
§Examples
Sourcepub fnmap<U>(this:Arc<T>, f: implFnOnce(&T) -> U) ->Arc<U>
🔬This is a nightly-only experimental API. (smart_pointer_try_map #144419)
pub fnmap<U>(this:Arc<T>, f: implFnOnce(&T) -> U) ->Arc<U>
smart_pointer_try_map #144419)Maps the value in anArc, reusing the allocation if possible.
f is called on a reference to the value in theArc, and the result is returned, also inanArc.
Note: this is an associated function, which means that you haveto call it asArc::map(a, f) instead ofr.map(a). Thisis so that there is no conflict with a method on the inner type.
§Examples
Sourcepub fntry_map<R>( this:Arc<T>, f: implFnOnce(&T) -> R,) -> <<R asTry>::Residual asResidual<Arc<<R asTry>::Output>>>::TryType
🔬This is a nightly-only experimental API. (smart_pointer_try_map #144419)
pub fntry_map<R>( this:Arc<T>, f: implFnOnce(&T) -> R,) -> <<R asTry>::Residual asResidual<Arc<<R asTry>::Output>>>::TryType
smart_pointer_try_map #144419)Attempts to map the value in anArc, reusing the allocation if possible.
f is called on a reference to the value in theArc, and if the operation succeeds, theresult is returned, also in anArc.
Note: this is an associated function, which means that you haveto call it asArc::try_map(a, f) instead ofa.try_map(f). Thisis so that there is no conflict with a method on the inner type.
§Examples
Source§impl<T, A>Arc<T, A>where A:Allocator,
impl<T, A>Arc<T, A>where A:Allocator,
Sourcepub fnnew_in(data: T, alloc: A) ->Arc<T, A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnnew_in(data: T, alloc: A) ->Arc<T, A>
allocator_api #32838)Constructs a newArc<T> in the provided allocator.
§Examples
Sourcepub fnnew_uninit_in(alloc: A) ->Arc<MaybeUninit<T>, A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnnew_uninit_in(alloc: A) ->Arc<MaybeUninit<T>, A>
allocator_api #32838)Constructs a newArc with uninitialized contents in the provided allocator.
§Examples
Sourcepub fnnew_zeroed_in(alloc: A) ->Arc<MaybeUninit<T>, A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnnew_zeroed_in(alloc: A) ->Arc<MaybeUninit<T>, A>
allocator_api #32838)Constructs a newArc with uninitialized contents, with the memorybeing filled with0 bytes, in the provided allocator.
SeeMaybeUninit::zeroed for examples of correct and incorrect usageof this method.
§Examples
Sourcepub fnnew_cyclic_in<F>(data_fn: F, alloc: A) ->Arc<T, A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnnew_cyclic_in<F>(data_fn: F, alloc: A) ->Arc<T, A>
allocator_api #32838)Constructs a newArc<T, A> in the given allocator while giving you aWeak<T, A> to the allocation,to allow you to construct aT which holds a weak pointer to itself.
Generally, a structure circularly referencing itself, either directly orindirectly, should not hold a strong reference to itself to prevent a memory leak.Using this function, you get access to the weak pointer during theinitialization ofT, before theArc<T, A> is created, such that you canclone and store it inside theT.
new_cyclic_in first allocates the managed allocation for theArc<T, A>,then calls your closure, giving it aWeak<T, A> to this allocation,and only afterwards completes the construction of theArc<T, A> by placingtheT returned from your closure into the allocation.
Since the newArc<T, A> is not fully-constructed untilArc<T, A>::new_cyclic_inreturns, callingupgrade on the weak reference inside your closure willfail and result in aNone value.
§Panics
Ifdata_fn panics, the panic is propagated to the caller, and thetemporaryWeak<T> is dropped normally.
§Example
Seenew_cyclic
Sourcepub fnpin_in(data: T, alloc: A) ->Pin<Arc<T, A>>where A: 'static,
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnpin_in(data: T, alloc: A) ->Pin<Arc<T, A>>where A: 'static,
allocator_api #32838)Constructs a newPin<Arc<T, A>> in the provided allocator. IfT does not implementUnpin,thendata will be pinned in memory and unable to be moved.
Sourcepub fntry_pin_in(data: T, alloc: A) ->Result<Pin<Arc<T, A>>,AllocError>where A: 'static,
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_pin_in(data: T, alloc: A) ->Result<Pin<Arc<T, A>>,AllocError>where A: 'static,
allocator_api #32838)Constructs a newPin<Arc<T, A>> in the provided allocator, return an error if allocationfails.
Sourcepub fntry_new_in(data: T, alloc: A) ->Result<Arc<T, A>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_new_in(data: T, alloc: A) ->Result<Arc<T, A>,AllocError>
allocator_api #32838)Constructs a newArc<T, A> in the provided allocator, returning an error if allocation fails.
§Examples
Sourcepub fntry_new_uninit_in(alloc: A) ->Result<Arc<MaybeUninit<T>, A>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_new_uninit_in(alloc: A) ->Result<Arc<MaybeUninit<T>, A>,AllocError>
allocator_api #32838)Constructs a newArc with uninitialized contents, in the provided allocator, returning anerror if allocation fails.
§Examples
Sourcepub fntry_new_zeroed_in(alloc: A) ->Result<Arc<MaybeUninit<T>, A>,AllocError>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fntry_new_zeroed_in(alloc: A) ->Result<Arc<MaybeUninit<T>, A>,AllocError>
allocator_api #32838)Constructs a newArc with uninitialized contents, with the memorybeing filled with0 bytes, in the provided allocator, returning an error if allocationfails.
SeeMaybeUninit::zeroed for examples of correct and incorrect usageof this method.
§Examples
1.4.0 ·Sourcepub fntry_unwrap(this:Arc<T, A>) ->Result<T,Arc<T, A>>
pub fntry_unwrap(this:Arc<T, A>) ->Result<T,Arc<T, A>>
Returns the inner value, if theArc has exactly one strong reference.
Otherwise, anErr is returned with the sameArc that waspassed in.
This will succeed even if there are outstanding weak references.
It is strongly recommended to useArc::into_inner instead if you don’tkeep theArc in theErr case.Immediately dropping theErr-value, as the expressionArc::try_unwrap(this).ok() does, can cause the strong count todrop to zero and the inner value of theArc to be dropped.For instance, if two threads execute such an expression in parallel,there is a race condition without the possibility of unsafety:The threads could first both check whether they own the last instanceinArc::try_unwrap, determine that they both do not, and then bothdiscard and drop their instance in the call took.In this scenario, the value inside theArc is safely destroyedby exactly one of the threads, but neither thread will ever be ableto use the value.
§Examples
1.70.0 ·Sourcepub fninto_inner(this:Arc<T, A>) ->Option<T>
pub fninto_inner(this:Arc<T, A>) ->Option<T>
Returns the inner value, if theArc has exactly one strong reference.
Otherwise,None is returned and theArc is dropped.
This will succeed even if there are outstanding weak references.
IfArc::into_inner is called on every clone of thisArc,it is guaranteed that exactly one of the calls returns the inner value.This means in particular that the inner value is not dropped.
Arc::try_unwrap is conceptually similar toArc::into_inner, but itis meant for different use-cases. If used as a direct replacementforArc::into_inner anyway, such as with the expressionArc::try_unwrap(this).ok(), then it doesnot give the same guarantee as described in the previous paragraph.For more information, see the examples below and read the documentationofArc::try_unwrap.
§Examples
Minimal example demonstrating the guarantee thatArc::into_inner gives.
usestd::sync::Arc;letx = Arc::new(3);lety = Arc::clone(&x);// Two threads calling `Arc::into_inner` on both clones of an `Arc`:letx_thread = std::thread::spawn(|| Arc::into_inner(x));lety_thread = std::thread::spawn(|| Arc::into_inner(y));letx_inner_value = x_thread.join().unwrap();lety_inner_value = y_thread.join().unwrap();// One of the threads is guaranteed to receive the inner value:assert!(matches!( (x_inner_value, y_inner_value), (None,Some(3)) | (Some(3),None)));// The result could also be `(None, None)` if the threads called// `Arc::try_unwrap(x).ok()` and `Arc::try_unwrap(y).ok()` instead.A more practical example demonstrating the need forArc::into_inner:
usestd::sync::Arc;// Definition of a simple singly linked list using `Arc`:#[derive(Clone)]structLinkedList<T>(Option<Arc<Node<T>>>);structNode<T>(T,Option<Arc<Node<T>>>);// Dropping a long `LinkedList<T>` relying on the destructor of `Arc`// can cause a stack overflow. To prevent this, we can provide a// manual `Drop` implementation that does the destruction in a loop:impl<T> DropforLinkedList<T> {fndrop(&mutself) {letmutlink =self.0.take();while letSome(arc_node) = link.take() {if letSome(Node(_value, next)) = Arc::into_inner(arc_node) { link = next; } } }}// Implementation of `new` and `push` omittedimpl<T> LinkedList<T> {/* ... */}// The following code could have still caused a stack overflow// despite the manual `Drop` impl if that `Drop` impl had used// `Arc::try_unwrap(arc).ok()` instead of `Arc::into_inner(arc)`.// Create a long list and clone itletmutx = LinkedList::new();letsize =100000;foriin0..size { x.push(i);// Adds i to the front of x}lety = x.clone();// Drop the clones in parallelletx_thread = std::thread::spawn(|| drop(x));lety_thread = std::thread::spawn(|| drop(y));x_thread.join().unwrap();y_thread.join().unwrap();Source§impl<T>Arc<[T]>
impl<T>Arc<[T]>
1.82.0 ·Sourcepub fnnew_uninit_slice(len:usize) ->Arc<[MaybeUninit<T>]>
pub fnnew_uninit_slice(len:usize) ->Arc<[MaybeUninit<T>]>
Constructs a new atomically reference-counted slice with uninitialized contents.
§Examples
1.92.0 ·Sourcepub fnnew_zeroed_slice(len:usize) ->Arc<[MaybeUninit<T>]>
pub fnnew_zeroed_slice(len:usize) ->Arc<[MaybeUninit<T>]>
Constructs a new atomically reference-counted slice with uninitialized contents, with the memory beingfilled with0 bytes.
SeeMaybeUninit::zeroed for examples of correct andincorrect usage of this method.
§Examples
Sourcepub fninto_array<const N:usize>(self) ->Option<Arc<[T; N]>>
🔬This is a nightly-only experimental API. (alloc_slice_into_array #148082)
pub fninto_array<const N:usize>(self) ->Option<Arc<[T; N]>>
alloc_slice_into_array #148082)Converts the reference-counted slice into a reference-counted array.
This operation does not reallocate; the underlying array of the slice is simply reinterpreted as an array type.
IfN is not exactly equal to the length ofself, then this method returnsNone.
Source§impl<T, A>Arc<[T], A>where A:Allocator,
impl<T, A>Arc<[T], A>where A:Allocator,
Sourcepub fnnew_uninit_slice_in(len:usize, alloc: A) ->Arc<[MaybeUninit<T>], A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnnew_uninit_slice_in(len:usize, alloc: A) ->Arc<[MaybeUninit<T>], A>
allocator_api #32838)Constructs a new atomically reference-counted slice with uninitialized contents in theprovided allocator.
§Examples
#![feature(get_mut_unchecked)]#![feature(allocator_api)]usestd::sync::Arc;usestd::alloc::System;letmutvalues = Arc::<[u32],_>::new_uninit_slice_in(3, System);letvalues =unsafe{// Deferred initialization:Arc::get_mut_unchecked(&mutvalues)[0].as_mut_ptr().write(1); Arc::get_mut_unchecked(&mutvalues)[1].as_mut_ptr().write(2); Arc::get_mut_unchecked(&mutvalues)[2].as_mut_ptr().write(3); values.assume_init()};assert_eq!(*values, [1,2,3])Sourcepub fnnew_zeroed_slice_in(len:usize, alloc: A) ->Arc<[MaybeUninit<T>], A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnnew_zeroed_slice_in(len:usize, alloc: A) ->Arc<[MaybeUninit<T>], A>
allocator_api #32838)Constructs a new atomically reference-counted slice with uninitialized contents, with the memory beingfilled with0 bytes, in the provided allocator.
SeeMaybeUninit::zeroed for examples of correct andincorrect usage of this method.
§Examples
Source§impl<T, A>Arc<MaybeUninit<T>, A>where A:Allocator,
impl<T, A>Arc<MaybeUninit<T>, A>where A:Allocator,
1.82.0 ·Sourcepub unsafe fnassume_init(self) ->Arc<T, A>
pub unsafe fnassume_init(self) ->Arc<T, A>
Converts toArc<T>.
§Safety
As withMaybeUninit::assume_init,it is up to the caller to guarantee that the inner valuereally is in an initialized state.Calling this when the content is not yet fully initializedcauses immediate undefined behavior.
§Examples
Source§impl<T>Arc<T>where T:CloneToUninit + ?Sized,
impl<T>Arc<T>where T:CloneToUninit + ?Sized,
Sourcepub fnclone_from_ref(value:&T) ->Arc<T>
🔬This is a nightly-only experimental API. (clone_from_ref #149075)
pub fnclone_from_ref(value:&T) ->Arc<T>
clone_from_ref #149075)Constructs a newArc<T> with a clone ofvalue.
§Examples
Sourcepub fntry_clone_from_ref(value:&T) ->Result<Arc<T>,AllocError>
🔬This is a nightly-only experimental API. (clone_from_ref #149075)
pub fntry_clone_from_ref(value:&T) ->Result<Arc<T>,AllocError>
clone_from_ref #149075)Constructs a newArc<T> with a clone ofvalue, returning an error if allocation fails
§Examples
Source§impl<T, A>Arc<T, A>
impl<T, A>Arc<T, A>
Sourcepub fnclone_from_ref_in(value:&T, alloc: A) ->Arc<T, A>
🔬This is a nightly-only experimental API. (clone_from_ref #149075)
pub fnclone_from_ref_in(value:&T, alloc: A) ->Arc<T, A>
clone_from_ref #149075)Constructs a newArc<T> with a clone ofvalue in the provided allocator.
§Examples
Sourcepub fntry_clone_from_ref_in( value:&T, alloc: A,) ->Result<Arc<T, A>,AllocError>
🔬This is a nightly-only experimental API. (clone_from_ref #149075)
pub fntry_clone_from_ref_in( value:&T, alloc: A,) ->Result<Arc<T, A>,AllocError>
clone_from_ref #149075)Constructs a newArc<T> with a clone ofvalue in the provided allocator, returning an error if allocation fails
§Examples
Source§impl<T, A>Arc<[MaybeUninit<T>], A>where A:Allocator,
impl<T, A>Arc<[MaybeUninit<T>], A>where A:Allocator,
1.82.0 ·Sourcepub unsafe fnassume_init(self) ->Arc<[T], A>
pub unsafe fnassume_init(self) ->Arc<[T], A>
Converts toArc<[T]>.
§Safety
As withMaybeUninit::assume_init,it is up to the caller to guarantee that the inner valuereally is in an initialized state.Calling this when the content is not yet fully initializedcauses immediate undefined behavior.
§Examples
Source§impl<T>Arc<T>where T: ?Sized,
impl<T>Arc<T>where T: ?Sized,
1.17.0 ·Sourcepub unsafe fnfrom_raw(ptr:*const T) ->Arc<T>
pub unsafe fnfrom_raw(ptr:*const T) ->Arc<T>
Constructs anArc<T> from a raw pointer.
The raw pointer must have been previously returned by a call toArc<U>::into_raw with the following requirements:
- If
Uis sized, it must have the same size and alignment asT. Thisis trivially true ifUisT. - If
Uis unsized, its data pointer must have the same size andalignment asT. This is trivially true ifArc<U>was constructedthroughArc<T>and then converted toArc<U>through anunsizedcoercion.
Note that ifU orU’s data pointer is notT but has the same sizeand alignment, this is basically like transmuting references ofdifferent types. Seemem::transmute for more informationon what restrictions apply in this case.
The raw pointer must point to a block of memory allocated by the global allocator.
The user offrom_raw has to make sure a specific value ofT is onlydropped once.
This function is unsafe because improper use may lead to memory unsafety,even if the returnedArc<T> is never accessed.
§Examples
usestd::sync::Arc;letx = Arc::new("hello".to_owned());letx_ptr = Arc::into_raw(x);unsafe{// Convert back to an `Arc` to prevent leak.letx = Arc::from_raw(x_ptr);assert_eq!(&*x,"hello");// Further calls to `Arc::from_raw(x_ptr)` would be memory-unsafe.}// The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!Convert a slice back into its original array:
1.17.0 ·Sourcepub fninto_raw(this:Arc<T>) ->*const T
pub fninto_raw(this:Arc<T>) ->*const T
Consumes theArc, returning the wrapped pointer.
To avoid a memory leak the pointer must be converted back to anArc usingArc::from_raw.
§Examples
1.51.0 ·Sourcepub unsafe fnincrement_strong_count(ptr:*const T)
pub unsafe fnincrement_strong_count(ptr:*const T)
Increments the strong reference count on theArc<T> associated with theprovided pointer by one.
§Safety
The pointer must have been obtained throughArc::into_raw and must satisfy thesame layout requirements specified inArc::from_raw_in.The associatedArc instance must be valid (i.e. the strong count must be atleast 1) for the duration of this method, andptr must point to a block of memoryallocated by the global allocator.
§Examples
1.51.0 ·Sourcepub unsafe fndecrement_strong_count(ptr:*const T)
pub unsafe fndecrement_strong_count(ptr:*const T)
Decrements the strong reference count on theArc<T> associated with theprovided pointer by one.
§Safety
The pointer must have been obtained throughArc::into_raw and must satisfy thesame layout requirements specified inArc::from_raw_in.The associatedArc instance must be valid (i.e. the strong count must be atleast 1) when invoking this method, andptr must point to a block of memoryallocated by the global allocator. This method can be used to release the finalArc and backing storage, butshould not be called after the finalArc has beenreleased.
§Examples
usestd::sync::Arc;letfive = Arc::new(5);unsafe{letptr = Arc::into_raw(five); Arc::increment_strong_count(ptr);// Those assertions are deterministic because we haven't shared // the `Arc` between threads.letfive = Arc::from_raw(ptr);assert_eq!(2, Arc::strong_count(&five)); Arc::decrement_strong_count(ptr);assert_eq!(1, Arc::strong_count(&five));}Source§impl<T, A>Arc<T, A>
impl<T, A>Arc<T, A>
Sourcepub fnallocator(this: &Arc<T, A>) ->&A
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fnallocator(this: &Arc<T, A>) ->&A
allocator_api #32838)Returns a reference to the underlying allocator.
Note: this is an associated function, which means that you haveto call it asArc::allocator(&a) instead ofa.allocator(). Thisis so that there is no conflict with a method on the inner type.
Sourcepub fninto_raw_with_allocator(this:Arc<T, A>) -> (*const T, A)
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub fninto_raw_with_allocator(this:Arc<T, A>) -> (*const T, A)
allocator_api #32838)Consumes theArc, returning the wrapped pointer and allocator.
To avoid a memory leak the pointer must be converted back to anArc usingArc::from_raw_in.
§Examples
1.45.0 ·Sourcepub fnas_ptr(this: &Arc<T, A>) ->*const T
pub fnas_ptr(this: &Arc<T, A>) ->*const T
Provides a raw pointer to the data.
The counts are not affected in any way and theArc is not consumed. The pointer is valid foras long as there are strong counts in theArc.
§Examples
Sourcepub unsafe fnfrom_raw_in(ptr:*const T, alloc: A) ->Arc<T, A>
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub unsafe fnfrom_raw_in(ptr:*const T, alloc: A) ->Arc<T, A>
allocator_api #32838)Constructs anArc<T, A> from a raw pointer.
The raw pointer must have been previously returned by a call toArc<U, A>::into_raw with the following requirements:
- If
Uis sized, it must have the same size and alignment asT. Thisis trivially true ifUisT. - If
Uis unsized, its data pointer must have the same size andalignment asT. This is trivially true ifArc<U>was constructedthroughArc<T>and then converted toArc<U>through anunsizedcoercion.
Note that ifU orU’s data pointer is notT but has the same sizeand alignment, this is basically like transmuting references ofdifferent types. Seemem::transmute for more informationon what restrictions apply in this case.
The raw pointer must point to a block of memory allocated byalloc
The user offrom_raw has to make sure a specific value ofT is onlydropped once.
This function is unsafe because improper use may lead to memory unsafety,even if the returnedArc<T> is never accessed.
§Examples
#![feature(allocator_api)]usestd::sync::Arc;usestd::alloc::System;letx = Arc::new_in("hello".to_owned(), System);let(x_ptr, alloc) = Arc::into_raw_with_allocator(x);unsafe{// Convert back to an `Arc` to prevent leak.letx = Arc::from_raw_in(x_ptr, System);assert_eq!(&*x,"hello");// Further calls to `Arc::from_raw(x_ptr)` would be memory-unsafe.}// The memory was freed when `x` went out of scope above, so `x_ptr` is now dangling!Convert a slice back into its original array:
1.15.0 ·Sourcepub fnweak_count(this: &Arc<T, A>) ->usize
pub fnweak_count(this: &Arc<T, A>) ->usize
1.15.0 ·Sourcepub fnstrong_count(this: &Arc<T, A>) ->usize
pub fnstrong_count(this: &Arc<T, A>) ->usize
Sourcepub unsafe fnincrement_strong_count_in(ptr:*const T, alloc: A)where A:Clone,
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub unsafe fnincrement_strong_count_in(ptr:*const T, alloc: A)where A:Clone,
allocator_api #32838)Increments the strong reference count on theArc<T> associated with theprovided pointer by one.
§Safety
The pointer must have been obtained throughArc::into_raw and must satisfy thesame layout requirements specified inArc::from_raw_in.The associatedArc instance must be valid (i.e. the strong count must be atleast 1) for the duration of this method, andptr must point to a block of memoryallocated byalloc.
§Examples
#![feature(allocator_api)]usestd::sync::Arc;usestd::alloc::System;letfive = Arc::new_in(5, System);unsafe{let(ptr, _alloc) = Arc::into_raw_with_allocator(five); Arc::increment_strong_count_in(ptr, System);// This assertion is deterministic because we haven't shared // the `Arc` between threads.letfive = Arc::from_raw_in(ptr, System);assert_eq!(2, Arc::strong_count(&five));}Sourcepub unsafe fndecrement_strong_count_in(ptr:*const T, alloc: A)
🔬This is a nightly-only experimental API. (allocator_api #32838)
pub unsafe fndecrement_strong_count_in(ptr:*const T, alloc: A)
allocator_api #32838)Decrements the strong reference count on theArc<T> associated with theprovided pointer by one.
§Safety
The pointer must have been obtained throughArc::into_raw and must satisfy thesame layout requirements specified inArc::from_raw_in.The associatedArc instance must be valid (i.e. the strong count must be atleast 1) when invoking this method, andptr must point to a block of memoryallocated byalloc. This method can be used to release the finalArc and backing storage, butshould not be called after the finalArc has beenreleased.
§Examples
#![feature(allocator_api)]usestd::sync::Arc;usestd::alloc::System;letfive = Arc::new_in(5, System);unsafe{let(ptr, _alloc) = Arc::into_raw_with_allocator(five); Arc::increment_strong_count_in(ptr, System);// Those assertions are deterministic because we haven't shared // the `Arc` between threads.letfive = Arc::from_raw_in(ptr, System);assert_eq!(2, Arc::strong_count(&five)); Arc::decrement_strong_count_in(ptr, System);assert_eq!(1, Arc::strong_count(&five));}Source§impl<T, A>Arc<T, A>
impl<T, A>Arc<T, A>
1.4.0 ·Sourcepub fnmake_mut(this: &mutArc<T, A>) ->&mut T
pub fnmake_mut(this: &mutArc<T, A>) ->&mut T
Makes a mutable reference into the givenArc.
If there are otherArc pointers to the same allocation, thenmake_mut willclone the inner value to a new allocation to ensure unique ownership. This is alsoreferred to as clone-on-write.
However, if there are no otherArc pointers to this allocation, but someWeakpointers, then theWeak pointers will be dissociated and the inner value will notbe cloned.
See alsoget_mut, which will fail rather than cloning the inner valueor dissociatingWeak pointers.
§Examples
usestd::sync::Arc;letmutdata = Arc::new(5);*Arc::make_mut(&mutdata) +=1;// Won't clone anythingletmutother_data = Arc::clone(&data);// Won't clone inner data*Arc::make_mut(&mutdata) +=1;// Clones inner data*Arc::make_mut(&mutdata) +=1;// Won't clone anything*Arc::make_mut(&mutother_data)*=2;// Won't clone anything// Now `data` and `other_data` point to different allocations.assert_eq!(*data,8);assert_eq!(*other_data,12);Weak pointers will be dissociated:
Source§impl<T, A>Arc<T, A>
impl<T, A>Arc<T, A>
1.76.0 ·Sourcepub fnunwrap_or_clone(this:Arc<T, A>) -> T
pub fnunwrap_or_clone(this:Arc<T, A>) -> T
If we have the only reference toT then unwrap it. Otherwise, cloneT and return theclone.
Assumingarc_t is of typeArc<T>, this function is functionally equivalent to(*arc_t).clone(), but will avoid cloning the inner value where possible.
§Examples
letinner = String::from("test");letptr = inner.as_ptr();letarc = Arc::new(inner);letinner = Arc::unwrap_or_clone(arc);// The inner value was not clonedassert!(ptr::eq(ptr, inner.as_ptr()));letarc = Arc::new(inner);letarc2 = arc.clone();letinner = Arc::unwrap_or_clone(arc);// Because there were 2 references, we had to clone the inner value.assert!(!ptr::eq(ptr, inner.as_ptr()));// `arc2` is the last reference, so when we unwrap it we get back// the original `String`.letinner = Arc::unwrap_or_clone(arc2);assert!(ptr::eq(ptr, inner.as_ptr()));Source§impl<T, A>Arc<T, A>
impl<T, A>Arc<T, A>
1.4.0 ·Sourcepub fnget_mut(this: &mutArc<T, A>) ->Option<&mut T>
pub fnget_mut(this: &mutArc<T, A>) ->Option<&mut T>
Sourcepub unsafe fnget_mut_unchecked(this: &mutArc<T, A>) ->&mut T
🔬This is a nightly-only experimental API. (get_mut_unchecked #63292)
pub unsafe fnget_mut_unchecked(this: &mutArc<T, A>) ->&mut T
get_mut_unchecked #63292)Returns a mutable reference into the givenArc,without any check.
See alsoget_mut, which is safe and does appropriate checks.
§Safety
If any otherArc orWeak pointers to the same allocation exist, thenthey must not be dereferenced or have active borrows for the durationof the returned borrow, and their inner type must be exactly the same as theinner type of this Arc (including lifetimes). This is trivially the case if nosuch pointers exist, for example immediately afterArc::new.
§Examples
#![feature(get_mut_unchecked)]usestd::sync::Arc;letmutx = Arc::new(String::new());unsafe{ Arc::get_mut_unchecked(&mutx).push_str("foo")}assert_eq!(*x,"foo");OtherArc pointers to the same allocation must be to the same type.
#![feature(get_mut_unchecked)]usestd::sync::Arc;letx: Arc<str> = Arc::from("Hello, world!");letmuty: Arc<[u8]> = x.clone().into();unsafe{// this is Undefined Behavior, because x's inner type is str, not [u8]Arc::get_mut_unchecked(&muty).fill(0xff);// 0xff is invalid in UTF-8}println!("{}",&*x);// Invalid UTF-8 in a strOtherArc pointers to the same allocation must be to the exact same type, including lifetimes.
#![feature(get_mut_unchecked)]usestd::sync::Arc;letx: Arc<&str> = Arc::new("Hello, world!");{lets = String::from("Oh, no!");letmuty: Arc<&str> = x.clone();unsafe{// this is Undefined Behavior, because x's inner type // is &'long str, not &'short str*Arc::get_mut_unchecked(&muty) =&s; }}println!("{}",&*x);// Use-after-freeSourcepub fnis_unique(this: &Arc<T, A>) ->bool
🔬This is a nightly-only experimental API. (arc_is_unique #138938)
pub fnis_unique(this: &Arc<T, A>) ->bool
arc_is_unique #138938)Determine whether this is the unique reference to the underlying data.
Returnstrue if there are no otherArc orWeak pointers to the same allocation;returnsfalse otherwise.
If this function returnstrue, then is guaranteed to be safe to callget_mut_uncheckedon thisArc, so long as no clones occur in between.
§Examples
#![feature(arc_is_unique)]usestd::sync::Arc;letx = Arc::new(3);assert!(Arc::is_unique(&x));lety = Arc::clone(&x);assert!(!Arc::is_unique(&x));drop(y);// Weak references also count, because they could be upgraded at any time.letz = Arc::downgrade(&x);assert!(!Arc::is_unique(&x));§Pointer invalidation
This function will always return the same value asArc::get_mut(arc).is_some(). However,unlike that operation it does not produce any mutable references to the underlying data,meaning no pointers to the data inside theArc are invalidated by the call. Thus, thefollowing code is valid, even though it would be UB if it usedArc::get_mut:
#![feature(arc_is_unique)]usestd::sync::Arc;letarc = Arc::new(5);letpointer:*consti32 =&*arc;assert!(Arc::is_unique(&arc));assert_eq!(unsafe{*pointer },5);§Atomic orderings
Concurrent drops to otherArc pointers to the same allocation will synchronize with thiscall - that is, this call performs anAcquire operation on the underlying strong and weakref counts. This ensures that callingget_mut_unchecked is safe.
Note that this operation requires locking the weak ref count, so concurrent calls todowngrade may spin-loop for a short period of time.
Source§impl<A>Arc<dynAny +Sync +Send, A>where A:Allocator,
impl<A>Arc<dynAny +Sync +Send, A>where A:Allocator,
1.29.0 ·Sourcepub fndowncast<T>(self) ->Result<Arc<T, A>,Arc<dynAny +Sync +Send, A>>
pub fndowncast<T>(self) ->Result<Arc<T, A>,Arc<dynAny +Sync +Send, A>>
Attempts to downcast theArc<dyn Any + Send + Sync> to a concrete type.
§Examples
Sourcepub unsafe fndowncast_unchecked<T>(self) ->Arc<T, A>
🔬This is a nightly-only experimental API. (downcast_unchecked #90850)
pub unsafe fndowncast_unchecked<T>(self) ->Arc<T, A>
downcast_unchecked #90850)Downcasts theArc<dyn Any + Send + Sync> to a concrete type.
For a safe alternative seedowncast.
§Examples
#![feature(downcast_unchecked)]usestd::any::Any;usestd::sync::Arc;letx: Arc<dynAny + Send + Sync> = Arc::new(1_usize);unsafe{assert_eq!(*x.downcast_unchecked::<usize>(),1);}§Safety
The contained value must be of typeT. Calling this methodwith the incorrect type isundefined behavior.
Trait Implementations§
Source§impl<T, A>Allocator forArc<T, A>
impl<T, A>Allocator forArc<T, A>
Source§fnallocate(&self, layout:Layout) ->Result<NonNull<[u8]>,AllocError>
fnallocate(&self, layout:Layout) ->Result<NonNull<[u8]>,AllocError>
allocator_api #32838)Source§fnallocate_zeroed(&self, layout:Layout) ->Result<NonNull<[u8]>,AllocError>
fnallocate_zeroed(&self, layout:Layout) ->Result<NonNull<[u8]>,AllocError>
allocator_api #32838)allocate, but also ensures that the returned memory is zero-initialized.Read moreSource§unsafe fndeallocate(&self, ptr:NonNull<u8>, layout:Layout)
unsafe fndeallocate(&self, ptr:NonNull<u8>, layout:Layout)
allocator_api #32838)ptr.Read moreSource§unsafe fngrow( &self, ptr:NonNull<u8>, old_layout:Layout, new_layout:Layout,) ->Result<NonNull<[u8]>,AllocError>
unsafe fngrow( &self, ptr:NonNull<u8>, old_layout:Layout, new_layout:Layout,) ->Result<NonNull<[u8]>,AllocError>
allocator_api #32838)Source§unsafe fngrow_zeroed( &self, ptr:NonNull<u8>, old_layout:Layout, new_layout:Layout,) ->Result<NonNull<[u8]>,AllocError>
unsafe fngrow_zeroed( &self, ptr:NonNull<u8>, old_layout:Layout, new_layout:Layout,) ->Result<NonNull<[u8]>,AllocError>
allocator_api #32838)grow, but also ensures that the new contents are set to zero before beingreturned.Read more1.64.0 ·Source§impl<T:AsFd + ?Sized>AsFd forArc<T>
Available onUnix or HermitCore ortarget_os=trusty or WASI ortarget_os=motor only.This impl allows implementing traits that requireAsFd on Arc.
impl<T:AsFd + ?Sized>AsFd forArc<T>
target_os=trusty or WASI ortarget_os=motor only.This impl allows implementing traits that requireAsFd on Arc.
Source§fnas_fd(&self) ->BorrowedFd<'_>
fnas_fd(&self) ->BorrowedFd<'_>
1.71.0 ·Source§impl<T:AsHandle + ?Sized>AsHandle forArc<T>
Available onWindows only.This impl allows implementing traits that requireAsHandle on Arc.
impl<T:AsHandle + ?Sized>AsHandle forArc<T>
This impl allows implementing traits that requireAsHandle on Arc.
Source§fnas_handle(&self) ->BorrowedHandle<'_>
fnas_handle(&self) ->BorrowedHandle<'_>
1.63.0 ·Source§impl<T:AsRawFd>AsRawFd forArc<T>
Available onUnix or HermitCore ortarget_os=trusty or WASI ortarget_os=motor only.This impl allows implementing traits that requireAsRawFd on Arc.
impl<T:AsRawFd>AsRawFd forArc<T>
target_os=trusty or WASI ortarget_os=motor only.This impl allows implementing traits that requireAsRawFd on Arc.
1.71.0 ·Source§impl<T:AsSocket>AsSocket forArc<T>
Available onWindows only.This impl allows implementing traits that requireAsSocket on Arc.
impl<T:AsSocket>AsSocket forArc<T>
This impl allows implementing traits that requireAsSocket on Arc.
Source§fnas_socket(&self) ->BorrowedSocket<'_>
fnas_socket(&self) ->BorrowedSocket<'_>
1.0.0 ·Source§impl<T, A>Clone forArc<T, A>
impl<T, A>Clone forArc<T, A>
1.0.0 ·Source§impl<T, A>Drop forArc<T, A>
impl<T, A>Drop forArc<T, A>
1.52.0 ·Source§impl<T>Error forArc<T>
impl<T>Error forArc<T>
Source§fncause(&self) ->Option<&dynError>
fncause(&self) ->Option<&dynError>
Source§fnsource(&self) ->Option<&(dynError + 'static)>
fnsource(&self) ->Option<&(dynError + 'static)>
Source§fnprovide<'a>(&'a self, req: &mutRequest<'a>)
fnprovide<'a>(&'a self, req: &mutRequest<'a>)
error_generic_member_access #99301)1.0.0 ·Source§fndescription(&self) -> &str
fndescription(&self) -> &str
Source§implFrom<Arc<[u8]>> forArc<ByteStr>
Available onnon-no_rc and non-no_sync andtarget_has_atomic=ptr only.
implFrom<Arc<[u8]>> forArc<ByteStr>
no_rc and non-no_sync andtarget_has_atomic=ptr only.Source§implFrom<Arc<ByteStr>> forArc<[u8]>
Available onnon-no_rc and non-no_sync andtarget_has_atomic=ptr only.
implFrom<Arc<ByteStr>> forArc<[u8]>
no_rc and non-no_sync andtarget_has_atomic=ptr only.1.37.0 ·Source§impl<T>FromIterator<T> forArc<[T]>
impl<T>FromIterator<T> forArc<[T]>
Source§fnfrom_iter<I>(iter: I) ->Arc<[T]>where I:IntoIterator<Item = T>,
fnfrom_iter<I>(iter: I) ->Arc<[T]>where I:IntoIterator<Item = T>,
Takes each element in theIterator and collects it into anArc<[T]>.
§Performance characteristics
§The general case
In the general case, collecting intoArc<[T]> is done by firstcollecting into aVec<T>. That is, when writing the following:
this behaves as if we wrote:
letevens: Arc<[u8]> = (0..10).filter(|&x| x %2==0) .collect::<Vec<_>>()// The first set of allocations happens here..into();// A second allocation for `Arc<[T]>` happens here.This will allocate as many times as needed for constructing theVec<T>and then it will allocate once for turning theVec<T> into theArc<[T]>.
§Iterators of known length
When yourIterator implementsTrustedLen and is of an exact size,a single allocation will be made for theArc<[T]>. For example:
1.0.0 ·Source§impl<T, A>Ord forArc<T, A>
impl<T, A>Ord forArc<T, A>
Source§fncmp(&self, other: &Arc<T, A>) ->Ordering
fncmp(&self, other: &Arc<T, A>) ->Ordering
1.21.0 ·Source§fnmax(self, other: Self) -> Selfwhere Self:Sized,
fnmax(self, other: Self) -> Selfwhere Self:Sized,
1.0.0 ·Source§impl<T, A>PartialEq forArc<T, A>
impl<T, A>PartialEq forArc<T, A>
Source§fneq(&self, other: &Arc<T, A>) ->bool
fneq(&self, other: &Arc<T, A>) ->bool
Equality for twoArcs.
TwoArcs are equal if their inner values are equal, even if they arestored in different allocation.
IfT also implementsEq (implying reflexivity of equality),twoArcs that point to the same allocation are always equal.
§Examples
1.0.0 ·Source§impl<T, A>PartialOrd forArc<T, A>
impl<T, A>PartialOrd forArc<T, A>
Source§fnpartial_cmp(&self, other: &Arc<T, A>) ->Option<Ordering>
fnpartial_cmp(&self, other: &Arc<T, A>) ->Option<Ordering>
Partial comparison for twoArcs.
The two are compared by callingpartial_cmp() on their inner values.
§Examples
Source§fnlt(&self, other: &Arc<T, A>) ->bool
fnlt(&self, other: &Arc<T, A>) ->bool
Source§fnle(&self, other: &Arc<T, A>) ->bool
fnle(&self, other: &Arc<T, A>) ->bool
‘Less than or equal to’ comparison for twoArcs.
The two are compared by calling<= on their inner values.
§Examples
1.73.0 ·Source§implRead forArc<File>
implRead forArc<File>
Source§fnread(&mut self, buf: &mut [u8]) ->Result<usize>
fnread(&mut self, buf: &mut [u8]) ->Result<usize>
Source§fnread_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) ->Result<usize>
fnread_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) ->Result<usize>
read, except that it reads into a slice of buffers.Read moreSource§fnread_buf(&mut self, cursor:BorrowedCursor<'_>) ->Result<()>
fnread_buf(&mut self, cursor:BorrowedCursor<'_>) ->Result<()>
read_buf #78485)Source§fnis_read_vectored(&self) ->bool
fnis_read_vectored(&self) ->bool
can_vector #69941)Source§fnread_to_end(&mut self, buf: &mutVec<u8>) ->Result<usize>
fnread_to_end(&mut self, buf: &mutVec<u8>) ->Result<usize>
buf.Read moreSource§fnread_to_string(&mut self, buf: &mutString) ->Result<usize>
fnread_to_string(&mut self, buf: &mutString) ->Result<usize>
buf.Read more1.6.0 ·Source§fnread_exact(&mut self, buf: &mut [u8]) ->Result<()>
fnread_exact(&mut self, buf: &mut [u8]) ->Result<()>
buf.Read moreSource§fnread_buf_exact(&mut self, cursor:BorrowedCursor<'_>) ->Result<()>
fnread_buf_exact(&mut self, cursor:BorrowedCursor<'_>) ->Result<()>
read_buf #78485)cursor.Read more1.0.0 ·Source§fnby_ref(&mut self) -> &mut Selfwhere Self:Sized,
fnby_ref(&mut self) -> &mut Selfwhere Self:Sized,
Read.Read more1.0.0 ·Source§fnchain<R:Read>(self, next: R) ->Chain<Self, R>ⓘwhere Self:Sized,
fnchain<R:Read>(self, next: R) ->Chain<Self, R>ⓘwhere Self:Sized,
1.73.0 ·Source§implSeek forArc<File>
implSeek forArc<File>
Source§fnseek(&mut self, pos:SeekFrom) ->Result<u64>
fnseek(&mut self, pos:SeekFrom) ->Result<u64>
Source§fnstream_len(&mut self) ->Result<u64>
fnstream_len(&mut self) ->Result<u64>
seek_stream_len #59359)1.73.0 ·Source§implWrite forArc<File>
implWrite forArc<File>
Source§fnwrite(&mut self, buf: &[u8]) ->Result<usize>
fnwrite(&mut self, buf: &[u8]) ->Result<usize>
Source§fnis_write_vectored(&self) ->bool
fnis_write_vectored(&self) ->bool
can_vector #69941)Source§fnflush(&mut self) ->Result<()>
fnflush(&mut self) ->Result<()>
1.0.0 ·Source§fnwrite_all(&mut self, buf: &[u8]) ->Result<()>
fnwrite_all(&mut self, buf: &[u8]) ->Result<()>
Source§fnwrite_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) ->Result<()>
fnwrite_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) ->Result<()>
write_all_vectored #70436)