Struct abi_stable::std_types::RArc [−][src]
#[repr(C)]pub struct RArc<T> { /* fields omitted */ }
Expand description
Ffi-safe version of std::sync::Arc
Example
Using an RArc<RMutex<RVec<u32>>>
to get a list populated from multiple threads.
use abi_stable::{
external_types::RMutex,
std_types::{RArc, RVec},
};
use std::thread;
let arc = RArc::new(RMutex::new(RVec::new()));
{
let arc2 = RArc::clone(&arc);
assert!(std::ptr::eq(&*arc, &*arc2));
}
let mut guards = Vec::new();
for i in 0..10_u64 {
let arc = RArc::clone(&arc);
guards.push(thread::spawn(move || {
for j in 0..100_u64 {
arc.lock().push(i * 100 + j);
}
}));
}
for guard in guards {
guard.join().unwrap();
}
let mut vec = RArc::try_unwrap(arc)
.ok()
.expect("All the threads were joined, so this must be the only RArc")
.into_inner();
vec.sort();
assert_eq!(vec, (0..1000).collect::<RVec<_>>());
Implementations
Converts this RArc<T>
into an Arc<T>
Allocators
RArc<T>
cannot always be converted to an Arc<T>
,
because their allocators might be different.
When is T cloned
T
is cloned if the current dynamic_library/executable is
not the one that created the RArc<T>
,
and the strong count is greater than 1.
Example
use abi_stable::std_types::RArc;
use std::sync::Arc;
let arc = RArc::new(100);
assert_eq!(RArc::into_arc(arc), Arc::new(100));
Attempts to unwrap this RArc<T>
into a T
,
returns Err(self)
if the RArc<T>
’s strong count is greater than 1.
Example
use abi_stable::std_types::RArc;
let arc0 = RArc::new(100);
assert_eq!(RArc::try_unwrap(arc0), Ok(100));
let arc1 = RArc::new(100);
let arc1_clone = RArc::clone(&arc1);
assert_eq!(RArc::try_unwrap(arc1), Err(arc1_clone.clone()));
Attempts to create a mutable reference to T
,
failing if the RArc<T>
’s strong count is greater than 1.
Example
use abi_stable::std_types::RArc;
let mut arc0 = RArc::new(100);
*RArc::get_mut(&mut arc0).unwrap() += 400;
assert_eq!(*arc0, 500);
let mut arc1 = RArc::new(100);
let _arc1_clone = RArc::clone(&arc1);
assert_eq!(RArc::get_mut(&mut arc1), None);
Makes a mutable reference to T
.
If there are other RArc<T>
s pointing to the same value,
then T
is cloned into a new RArc<T>
to ensure unique ownership of the value.
Postconditions
After this call, the strong count of this
will be 1,
because either it was 1 before the call,
or because a new RArc<T>
was created to ensure unique ownership of T
.
Example
use abi_stable::std_types::RArc;
let mut arc0 = RArc::new(100);
*RArc::make_mut(&mut arc0) += 400;
assert_eq!(*arc0, 500);
let mut arc1 = RArc::new(100);
let arc1_clone = RArc::clone(&arc1);
*RArc::make_mut(&mut arc1) += 400;
assert_eq!(*arc1, 500);
assert_eq!(*arc1_clone, 100);
Gets the number of RArc
that point to the value.
Example
use abi_stable::std_types::RArc;
let arc = RArc::new(0);
assert_eq!(RArc::strong_count(&arc), 1);
let clone = RArc::clone(&arc);
assert_eq!(RArc::strong_count(&arc), 2);
Gets the number of std::sync::Weak
that point to the value.
Example
use abi_stable::std_types::RArc;
use std::sync::Arc;
let rustarc = Arc::new(0);
let arc = RArc::from(rustarc.clone());
assert_eq!(RArc::weak_count(&arc), 0);
let weak_0 = Arc::downgrade(&rustarc);
assert_eq!(RArc::weak_count(&arc), 1);
let weak_1 = Arc::downgrade(&rustarc);
assert_eq!(RArc::weak_count(&arc), 2);
Trait Implementations
type TransmutedPtr = RArc<O>
type TransmutedPtr = RArc<O>
The type of the pointer after it’s element type has been changed.
Transmutes the element type of this pointer.. Read more
Deserialize this value from the given Serde deserializer. Read more
type Kind = PK_SmartPointer
type Kind = PK_SmartPointer
The kind of the pointer. Read more
type StaticEquivalent = _static_RArc<__GetStaticEquivalent<T>>
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
type IsNonZeroType = False
type IsNonZeroType = False
Whether this type has a single invalid bit-pattern. Read more
The layout of the type provided by implementors.
const
-equivalents of the associated types.
Auto Trait Implementations
impl<T> RefUnwindSafe for RArc<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for RArc<T> where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
type ROwned = T
type ROwned = T
The owned type, stored in RCow::Owned
type ForSelf = WithMetadata_<T, T>
type ForSelf = WithMetadata_<T, T>
This is always WithMetadata_<Self, Self>
Compares the address of self
with the address of other
. Read more
Emulates the pipeline operator, allowing method syntax in more places. Read more
The same as piped
except that the function takes &Self
Useful for functions that take &Self
instead of Self
. Read more
The same as piped
, except that the function takes &mut Self
.
Useful for functions that take &mut Self
instead of Self
. Read more
Mutates self using a closure taking self by mutable reference, passing it along the method chain. Read more
Observes the value of self, passing it along unmodified. Useful in long method chains. Read more
Performs a conversion with Into
.
using the turbofish .into_::<_>()
syntax. Read more
Performs a reference to reference conversion with AsRef
,
using the turbofish .as_ref_::<_>()
syntax. Read more
Performs a mutable reference to mutable reference conversion with AsMut
,
using the turbofish .as_mut_::<_>()
syntax. Read more
Returns the previous character boundary, stopping at 0. Read more
Returns the next character boundary. Read more
Returns the closest characted boundary left of index
(including index
). Read more
Returns the closest characted boundary right of index
(including index
). Read more
fn split_while<P, T>(&'a self, mapper: P) -> SplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
fn split_while<P, T>(&'a self, mapper: P) -> SplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
Returns an iterator over substrings whose characters were mapped to
the same key by mapper
. Read more
fn rsplit_while<P, T>(&'a self, mapper: P) -> RSplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
fn rsplit_while<P, T>(&'a self, mapper: P) -> RSplitWhile<'a, P, T> where
T: Eq + Clone,
P: FnMut(char) -> T,
A variation of split_while
that iterates
from the right(the order of substrings is reversed). Read more
The byte index of the nth
character Read more
The byte index of the nth
character Read more
Returns a string containing the first n
chars. Read more
Returns a string containing the last n
chars Read more
Returns the string from the n
th character Read more
Returns the length of the string in utf16 Read more
Returns the character at the at_byte
index inside of the string,
returning None
if the index is outside the string. Read more
Returns an iterator over (index,char) pairs up to
(but not including) the char at the to
byte. Read more
Returns an iterator over (index, char) pairs, starting from the from
byte. Read more
alloc
only.Pads the string on the left with how_much
additional spaces. Read more
Returns a value that pads the string on the left with how_much
additional
spaces in its Display
impl. Read more
core_str_methods
or crate feature alloc
only.The indentation of the first line. Read more
core_str_methods
or crate feature alloc
only.The minimum indentation of the string, ignoring lines that only contain whitespace. Read more
core_str_methods
or crate feature alloc
only.The maximum indentation of the string, ignoring lines that only contain whitespace. Read more
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
unsafe fn transmute_element<T>(
self
) -> <Self as CanTransmuteElement<T>>::TransmutedPtr where
Self: CanTransmuteElement<T>,
Transmutes the element type of this pointer.. Read more
type Type = T
type Type = T
This is always Self
.
Converts a value back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
Converts a value back to the original type.
Converts a reference back to the original type.
Converts a mutable reference back to the original type.
alloc
only.Converts a box back to the original type.
alloc
only.Converts an Arc back to the original type.
alloc
only.Converts an Rc back to the original type.