[][src]Struct rc_box::ArcBox

#[repr(transparent)]pub struct ArcBox<T: ?Sized> { /* fields omitted */ }

Known unique version of Arc.

This type is guaranteed to have the same repr as Box<T>. (The heap layout is that of Arc<T>.)

Implementations

impl ArcBox<dyn Any + 'static>[src]

pub fn downcast<T>(self) -> Result<ArcBox<T>, Self> where
    T: Any
[src]

Attempt to downcast the box to a concrete type.

Examples

use std::any::Any;

fn print_if_string(value: ArcBox<dyn Any>) {
    if let Ok(string) = value.downcast::<String>() {
        println!("String ({}): {}", string.len(), string);
    }
}

let my_string = "Hello World".to_string();
let my_string: Arc<dyn Any> = Arc::new(my_string); 
print_if_string(my_string.try_into().unwrap());
let my_number: Arc<dyn Any> = Arc::new(0i8);
print_if_string(my_number.try_into().unwrap());

The unsizing as Arc is required until DST coercions are stabilized.

impl ArcBox<dyn Any + Send + 'static>[src]

pub fn downcast<T>(self) -> Result<ArcBox<T>, Self> where
    T: Any + Send
[src]

Attempt to downcast the box to a concrete type.

Examples

use std::any::Any;

fn print_if_string(value: ArcBox<dyn Any + Send>) {
    if let Ok(string) = value.downcast::<String>() {
        println!("String ({}): {}", string.len(), string);
    }
}

let my_string = "Hello World".to_string();
let my_string: Arc<dyn Any + Send> = Arc::new(my_string); 
print_if_string(my_string.try_into().unwrap());
let my_number: Arc<dyn Any + Send> = Arc::new(0i8);
print_if_string(my_number.try_into().unwrap());

The unsizing as Arc is required until DST coercions are stabilized.

impl ArcBox<dyn Any + Send + Sync + 'static>[src]

pub fn downcast<T>(self) -> Result<ArcBox<T>, Self> where
    T: Any + Send + Sync
[src]

Attempt to downcast the box to a concrete type.

Examples

use std::any::Any;

fn print_if_string(value: ArcBox<dyn Any + Send + Sync>) {
    if let Ok(string) = value.downcast::<String>() {
        println!("String ({}): {}", string.len(), string);
    }
}

let my_string = "Hello World".to_string();
let my_string: Arc<dyn Any + Send + Sync> = Arc::new(my_string); 
print_if_string(my_string.try_into().unwrap());
let my_number: Arc<dyn Any + Send + Sync> = Arc::new(0i8);
print_if_string(my_number.try_into().unwrap());

The unsizing as Arc is required until DST coercions are stabilized.

impl<T: ?Sized> ArcBox<T>[src]

pub unsafe fn from_raw(ptr: *const T) -> Self[src]

Construct an ArcBox from a raw pointer.

Safety

The raw pointer must have previously been acquired by a call to ArcBox::into_raw, or Arc::into_raw where the Arc is known unique.

pub fn get_mut(this: &mut Self) -> Option<&mut T>[src]

Deprecated:

Use DerefMut instead

Get a mutable reference into the ArcBox.

This method exists only for API compatibility with Arc. Use DerefMut instead.

pub fn get_mut_unchecked(this: &mut Self) -> &mut T[src]

Deprecated:

Use DerefMut instead

Get a mutable reference into the ArcBox.

This method exists only for API compatibility with Arc. Use DerefMut instead.

pub fn as_raw(this: &Self) -> NonNull<T>[src]

Returns a raw pointer to the object T pointed to by this ArcBox.

Note that this returns a ptr::NonNull, not a raw pointer. That makes this function equivalent to as_raw_non_null.

pub fn into_raw(this: Self) -> NonNull<T>[src]

Consume the ArcBox, returning the wrapped pointer.

To avoid a memory leak, the pointer must be converted back to a ArcBox, using ArcBox::from_raw, or directly into a Arc, using Arc::from_raw.

Note that this returns a ptr::NonNull, not a raw pointer. That makes this function equivalent to into_raw_non_null.

pub fn leak<'a>(this: Self) -> &'a mut T where
    T: 'a, 
[src]

Consume and leak the ArcBox.

pub fn new(data: T) -> Self where
    T: Sized
[src]

Create a new ArcBox.

pub fn pin(x: T) -> Pin<ArcBox<T>> where
    T: Sized
[src]

Construct a new Pin<ArcBox<T>>. If T does not implement Unpin, then the data will be pinned in memory and unable to be moved.

pub fn into_inner(this: Self) -> T where
    T: Sized
[src]

Deconstruct this ArcBox, returning the inner value.

Trait Implementations

impl<T: ?Sized> AsMut<T> for ArcBox<T>[src]

impl<T: ?Sized> AsRef<T> for ArcBox<T>[src]

impl<T: ?Sized> Borrow<T> for ArcBox<T>[src]

impl<T: ?Sized> BorrowMut<T> for ArcBox<T>[src]

impl<T: ?Sized> Debug for ArcBox<T> where
    T: Debug
[src]

impl<T: ?Sized> Deref for ArcBox<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T: ?Sized> DerefMut for ArcBox<T>[src]

impl<T: ?Sized> Display for ArcBox<T> where
    T: Display
[src]

impl<T: ?Sized> DoubleEndedIterator for ArcBox<T> where
    T: DoubleEndedIterator
[src]

impl<T: ?Sized> Drop for ArcBox<T>[src]

impl<T: ?Sized> Eq for ArcBox<T> where
    T: Eq
[src]

impl<T: ?Sized> ErasablePtr for ArcBox<T> where
    T: Erasable
[src]

impl<T: ?Sized> ExactSizeIterator for ArcBox<T> where
    T: ExactSizeIterator
[src]

impl<'_, T> From<&'_ [T]> for ArcBox<[T]> where
    T: Clone
[src]

impl<'_> From<&'_ str> for ArcBox<str>[src]

impl<T: ?Sized> From<ArcBox<T>> for Arc<T>[src]

impl<T: ?Sized> From<Box<T>> for ArcBox<T>[src]

impl From<String> for ArcBox<str>[src]

impl<T> From<T> for ArcBox<T>[src]

impl<T> From<Vec<T>> for ArcBox<[T]>[src]

impl<T> FromIterator<T> for ArcBox<[T]>[src]

impl<T: ?Sized> FusedIterator for ArcBox<T> where
    T: FusedIterator
[src]

impl<T: ?Sized> Hash for ArcBox<T> where
    T: Hash
[src]

impl<T: ?Sized> Hasher for ArcBox<T> where
    T: Hasher
[src]

impl<T: ?Sized> Iterator for ArcBox<T> where
    T: Iterator
[src]

type Item = T::Item

The type of the elements being iterated over.

impl<T: ?Sized> Ord for ArcBox<T> where
    T: Ord
[src]

impl<T: ?Sized, O> PartialEq<O> for ArcBox<T> where
    O: Deref,
    T: PartialEq<O::Target>, 
[src]

impl<T: ?Sized, O> PartialOrd<O> for ArcBox<T> where
    O: Deref,
    T: PartialOrd<O::Target>, 
[src]

impl<T: ?Sized> Pointer for ArcBox<T>[src]

impl<T: ?Sized> Send for ArcBox<T> where
    Box<T>: Send
[src]

impl<T: ?Sized> Sync for ArcBox<T> where
    Box<T>: Sync
[src]

impl<T: ?Sized> TryFrom<Arc<T>> for ArcBox<T>[src]

type Error = Arc<T>

The type returned in the event of a conversion error.

impl<T: ?Sized> Unpin for ArcBox<T>[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Erasable for T[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.