unchecked_mutable 0.1.0

Shared mutable without runtime cost
Documentation
  • Coverage
  • 100%
    5 out of 5 items documented1 out of 5 items with examples
  • Size
  • Source code size: 2.99 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.37 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • Documentation
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • KalitaAlexey

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