[][src]Struct rc_box::RcBox

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

Known unique version of Rc.

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

Implementations

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

pub fn downcast<T>(self) -> Result<RcBox<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: RcBox<dyn Any>) {
    if let Ok(string) = value.downcast::<String>() {
        println!("String ({}): {}", string.len(), string);
    }
}

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

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

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

pub fn downcast<T>(self) -> Result<RcBox<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: RcBox<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: Rc<dyn Any + Send> = Rc::new(my_string); 
print_if_string(my_string.try_into().unwrap());
let my_number: Rc<dyn Any + Send> = Rc::new(0i8);
print_if_string(my_number.try_into().unwrap());

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

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

pub fn downcast<T>(self) -> Result<RcBox<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: RcBox<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: Rc<dyn Any + Send + Sync> = Rc::new(my_string); 
print_if_string(my_string.try_into().unwrap());
let my_number: Rc<dyn Any + Send + Sync> = Rc::new(0i8);
print_if_string(my_number.try_into().unwrap());

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

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

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

Construct an RcBox from a raw pointer.

Safety

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

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

Deprecated:

Use DerefMut instead

Get a mutable reference into the RcBox.

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

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

Deprecated:

Use DerefMut instead

Get a mutable reference into the RcBox.

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

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

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

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 RcBox, returning the wrapped pointer.

To avoid a memory leak, the pointer must be converted back to a RcBox, using RcBox::from_raw, or directly into a Rc, using Rc::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 RcBox.

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

Create a new RcBox.

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

Construct a new Pin<RcBox<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 RcBox, returning the inner value.

Trait Implementations

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

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

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

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

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

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

type Target = T

The resulting type after dereferencing.

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

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

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

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

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

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

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

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

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

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

impl<T: ?Sized> From<RcBox<T>> for Rc<T>[src]

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

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

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

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

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

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

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

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

type Item = T::Item

The type of the elements being iterated over.

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

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

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

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

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

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

impl<T: ?Sized> TryFrom<Rc<T>> for RcBox<T>[src]

type Error = Rc<T>

The type returned in the event of a conversion error.

impl<T: ?Sized> Unpin for RcBox<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.