[−][src]Struct yewtil::ptr::Irc
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 Irc
s 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]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for Irc<T>
[src]
impl<T: Default> Default for Irc<T>
[src]
impl<T> Deref for Irc<T>
[src]
impl<T> Drop for Irc<T>
[src]
impl<T: Eq> Eq for Irc<T>
[src]
impl<T: Hash> Hash for Irc<T>
[src]
fn hash<H: Hasher>(&self, state: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T: Ord> Ord for Irc<T>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[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]
T: 'static + ?Sized,
impl<T> Any for T where
T: Any,
T: Any,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CloneAny for T where
T: Clone + Any,
T: Clone + Any,
impl<Q, K> Equivalent<K> for Q where
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
[src]
K: Borrow<Q> + ?Sized,
Q: Eq + ?Sized,
fn equivalent(&self, key: &K) -> bool
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,