[][src]Struct yewtil::ptr::Irc

pub struct Irc<T> { /* fields omitted */ }

Immutable Reference Counted pointer.

The Irc points to a value that cannot be mutated. If a Mrc and Irc point to the same value, mutating the value via the Mrc will clone and allocate, then mutate the value, leaving the value pointed to by the Irc alone.

Unless the Irc is unwrapped, that value is mutated, and another Irc is created using that value the Irc will guarantee that the value is not changed, and can be transparently passed to child components with knowledge that its value matches that of an original Mrc or Irc that it was cloned from.

This makes Ircs ideal for passing around immutable views to data through components in Yew, as cloning the Irc itself is cheap, and the Irc guarantees that its data cannot be changed by some intermediate component without obvious unwrap --> modify --> rewrap operations.

Implementations

impl<T> Irc<T>[src]

pub fn new(value: T) -> Self[src]

Allocates the value behind an Irc pointer.

pub fn try_unwrap(self) -> Result<T, Self>[src]

Tries to extract the value from the Irc, returning the Irc if there is one or more other smart pointers to the value.

Example

use yewtil::ptr::Irc;
let irc = Irc::new(0);

let clone = irc.clone();
let irc = irc.try_unwrap().expect_err("Should not be able to unwrap");

std::mem::drop(clone);
let value = irc.try_unwrap().expect("Should get value");

pub fn get_count(&self) -> usize[src]

Gets the reference count of the Irc.

An exclusive Irc will have a count of 1. The count is incremented on any cloning action and is decremented when drop is called.

Example

use yewtil::ptr::Irc;
let irc = Irc::new(0);
assert_eq!(irc.get_count(), 1);

let _clone = irc.clone();
assert_eq!(irc.get_count(), 2);

std::mem::drop(_clone);
assert_eq!(irc.get_count(), 1);

pub fn is_exclusive(&self) -> bool[src]

use yewtil::ptr::Irc;
let irc = Irc::new(0);
assert!(irc.is_exclusive());

let _clone = irc.clone();
assert!(!irc.is_exclusive());

std::mem::drop(_clone);
assert!(irc.is_exclusive());

impl<T: Clone> Irc<T>[src]

pub fn unwrap_clone(self) -> T[src]

Unwraps the value from the Irc, cloning the value instead if another Irc or Mrc points to the same value.

pub fn clone_inner(&self) -> T[src]

Clones the wrapped value of the Irc.

Trait Implementations

impl<T> AsRef<T> for Irc<T>[src]

impl<T> Borrow<T> for Irc<T>[src]

impl<T> Clone for Irc<T>[src]

impl<T: Debug> Debug for Irc<T>[src]

impl<T: Default> Default for Irc<T>[src]

impl<T> Deref for Irc<T>[src]

type Target = T

The resulting type after dereferencing.

impl<T> Drop for Irc<T>[src]

impl<T: Eq> Eq for Irc<T>[src]

impl<T: Hash> Hash for Irc<T>[src]

impl<T: Ord> Ord for Irc<T>[src]

impl<T: PartialEq> PartialEq<Irc<T>> for Irc<T>[src]

impl<T: PartialOrd> PartialOrd<Irc<T>> for Irc<T>[src]

Auto Trait Implementations

impl<T> !RefUnwindSafe for Irc<T>

impl<T> !Send for Irc<T>

impl<T> !Sync for Irc<T>

impl<T> Unpin for Irc<T>

impl<T> !UnwindSafe for Irc<T>

Blanket Implementations

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

impl<T> Any for T where
    T: Any

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

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

impl<T> CloneAny for T where
    T: Clone + Any

impl<Q, K> Equivalent<K> for Q where
    K: Borrow<Q> + ?Sized,
    Q: Eq + ?Sized
[src]

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.