#mutable #shared #run-time #unchecked

unchecked_mutable

Shared mutable without runtime cost

1 unstable release

Uses old Rust 2015

0.1.0 Dec 18, 2015

#6 in #unchecked

MIT license

3KB

Sometimes it is important to share something and avoid runtime costs. This crate for such purpose

Examples

extern crate unchecked_mutable;

use std::borrow::BorrowMut;
use unchecked_mutable::UncheckedMutable;

trait Drawable {
    fn draw(&mut self);
}

struct Image;

impl Drawable for Image {
    fn draw(&mut self) {
        println!("Draw image");
    }
}

fn show_example<'a>() {
    let data = {
        let image: UncheckedMutable<Image> = UncheckedMutable::new(Image);
        image.data()
    };

    let mut drawable: UncheckedMutable<Drawable> = UncheckedMutable::from_rc(data);
    let drawable: &mut (Drawable + 'a) = drawable.borrow_mut();
    drawable.draw();
}

fn main() {
    show_example();
}

No runtime deps