Trait Meta

Source
pub trait Meta {
    type Data;
}
Expand description

Defines constant metadata to be stored alongside the primary item in a KeyCell.

§Purpose

Metadata is constant data associated with a particular KeyCell. Its primary purpose is to provide references to other KeyCells. If these other KeyCells were instead stored inside the original KeyCell, then any access to those would require us to clone them out before use.

§Examples

The following example shows how we will need to clone out other because there is no way to access it after we have split this into a &KeyCell<_> and a &mut Key.

use mutcy::{Key, KeyCell, KeyMut};
use std::rc::Rc;

struct A {
    other: Rc<KeyCell<i32>>,
}

fn function(this: KeyMut<A>) {
    // We require this clone...
    let other = this.other.clone();
    // because we can no longer access `this`...
    let (_this, key) = Key::split(this);
    // to increment `other`.
    *other.borrow_mut(key) += 1;
}

Metadata solves the issue of requiring clones.

use mutcy::{Key, KeyCell, KeyMut, Meta};
use std::rc::Rc;

struct A {
    // ...
}

impl Meta for A {
    type Data = Rc<KeyCell<i32>>;
}

fn function(this: KeyMut<A>) {
    // We don't need to clone anything before splitting...
    let (input, key) = Key::split(this);
    // because we can now access the `KeyCell` metadata via `meta`.
    *input.meta().borrow_mut(key) += 1;
}

Required Associated Types§

Implementations on Foreign Types§

Source§

impl Meta for &str

Source§

impl Meta for bool

Source§

impl Meta for char

Source§

impl Meta for f32

Source§

impl Meta for f64

Source§

impl Meta for i8

Source§

impl Meta for i16

Source§

impl Meta for i32

Source§

impl Meta for i64

Source§

impl Meta for i128

Source§

impl Meta for isize

Source§

impl Meta for u8

Source§

impl Meta for u16

Source§

impl Meta for u32

Source§

impl Meta for u64

Source§

impl Meta for u128

Source§

impl Meta for ()

Source§

impl Meta for usize

Source§

impl Meta for String

Source§

impl<A> Meta for (A,)

Source§

impl<A, B> Meta for (A, B)

Source§

impl<A, B, C> Meta for (A, B, C)

Source§

impl<A, B, C, D> Meta for (A, B, C, D)

Source§

impl<A, B, C, D, E> Meta for (A, B, C, D, E)

Source§

impl<A, B, C, D, E, F> Meta for (A, B, C, D, E, F)

Source§

impl<T> Meta for Box<T>

Source§

impl<T> Meta for VecDeque<T>

Source§

impl<T> Meta for Rc<T>

Source§

impl<T> Meta for Weak<T>

Source§

impl<T> Meta for Vec<T>

Implementors§