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

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

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]

fn as_ref(&self) -> &T[src]

Performs the conversion.

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

fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

fn clone(&self) -> Self[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

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

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn default() -> Self[src]

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

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

type Target = T

The resulting type after dereferencing.

fn deref(&self) -> &Self::Target[src]

Dereferences the value.

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

fn drop(&mut self)[src]

Executes the destructor for this type. Read more

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

fn hash<H: Hasher>(&self, state: &mut H)[src]

Feeds this value into the given Hasher. Read more

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0[src]

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

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

fn cmp(&self, other: &Self) -> Ordering[src]

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

#[must_use]
fn max(self, other: Self) -> Self
1.21.0[src]

Compares and returns the maximum of two values. Read more

#[must_use]
fn min(self, other: Self) -> Self
1.21.0[src]

Compares and returns the minimum of two values. Read more

#[must_use]
fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]

Restrict a value to a certain interval. Read more

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

fn eq(&self, other: &Self) -> bool[src]

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

#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests for !=.

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

fn partial_cmp(&self, other: &Self) -> Option<Ordering>[src]

This method returns an ordering between self and other values if one exists. Read more

#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]

This method tests less than (for self and other) and is used by the < operator. Read more

#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]

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

#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]

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

impl<T: Eq> Eq 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]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

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

Immutably borrows from an owned value. Read more

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

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

Mutably borrows from an owned value. Read more

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

pub fn equivalent(&self, key: &K) -> bool[src]

Compare self to key and return true if they are equal.

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T, V> IntoOptPropValue<V> for T where
    T: IntoPropValue<Option<V>>, 
[src]

pub fn into_opt_prop_value(self) -> Option<V>[src]

Convert self to an optional value of a Properties struct.

impl<T> IntoPropValue<Option<T>> for T[src]

pub fn into_prop_value(self) -> Option<T>[src]

Convert self to a value of a Properties struct.

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

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

Convert self to a value of a Properties struct.

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

type Owned = T

The resulting type after obtaining ownership.

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

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

pub fn clone_into(&self, target: &mut T)[src]

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

recently added

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

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.

impl<T> Any for T where
    T: Any

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