Crate unchecked_mutable [] [src]

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();
}

Structs

UncheckedMutable

It may be cloned as many times as needed. It may be borrowed at once by multiple threads without any checks. It is up to crate user to prevent any data races