Module tinystd::rc[][src]

Special note on the phantom/marker data:

Without the PhantomData type, the compiler cannot know that the Rc owns T. This matters when lifetimes are considered. Imagining:

struct Foo<'a, T> {v: &mut T}
impl<T> Drop for Foo<T> {
    fn drop(&mut self) {
        self.v.do_some_stuff();
    }
}

fn main() {
    let (foo, t);
    // remember, the compiler drops in reverse order of declaration
    let t: String::from("ok");
    let foo = Rc::from(Foo { v: &mut t });
}

Without the marker in Rc, the compiler cannot know that it still holds the inner T. In other words, the marker tells the compiler to treat the Rc as though it owns a T; Dropping Rc must be handled (by the compiler) as though it may be dropping T. This is called the “drop check”. See the nomicon for details.

Structs

Rc

A Reference counted container for T