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

Constructs an RArc from a value.

Example
use abi_stable::std_types::RArc;

let arc = RArc::new(100);

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

Gets a const raw pointer to the value that this points to.

Converts this pointer to an RRef.

Performs the conversion.

Immutably borrows from an owned value. Read more

The type of the pointer after it’s element type has been changed.

Transmutes the element type of this pointer.. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Executes the destructor for this type. Read more

Performs the conversion.

Performs the conversion.

The kind of the pointer. Read more

What this pointer points to. Read more

The value-level version of the Kind associated type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

The #[repr(Rust)] equivalent.

Performs the conversion

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Formats the value using the given formatter.

Serialize this value into the given Serde serializer. Read more

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

The owned type, stored in RCow::Owned

The borrowed type, stored in RCow::Borrowed

Performs the conversion.

This is always WithMetadata_<Self, Self>

Performs the conversion.

Gets a reference to a field, determined by offset. Read more

Gets a muatble reference to a field, determined by offset. Read more

Gets a const pointer to a field, the field is determined by offset. Read more

Gets a mutable pointer to a field, determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

Replaces a field (determined by offset) with value, returning the previous value of the field. Read more

Swaps a field (determined by offset) with the same field in right. Read more

Gets a copy of a field (determined by offset). The field is determined by offset. Read more

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

Drops self using method notation. Alternative to std::mem::drop. 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

Returns an iterator over substrings whose characters were mapped to the same key by mapper. Read more

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 the nth character in the str. 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 nth 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

This is supported on crate feature 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

This is supported on core_str_methods or crate feature alloc only.

The indentation of the first line. Read more

This is supported on core_str_methods or crate feature alloc only.

The minimum indentation of the string, ignoring lines that only contain whitespace. Read more

This is supported on core_str_methods or crate feature alloc only.

The maximum indentation of the string, ignoring lines that only contain whitespace. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

Transmutes the element type of this pointer.. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

This is always Self.

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.

This is supported on crate feature alloc only.

Converts a box back to the original type.

This is supported on crate feature alloc only.

Converts an Arc back to the original type. Read more

This is supported on crate feature alloc only.

Converts an Rc back to the original type. Read more

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.

This is supported on crate feature alloc only.

Converts a box back to the original type.

This is supported on crate feature alloc only.

Converts an Arc back to the original type.

This is supported on crate feature alloc only.

Converts an Rc back to the original type.