Region Buffer

Linux build status Documentation Donate using Liberapay

A growable array allowing for multiple mutable non overlapping regions from the same Vec.

``` use region_buffer::RegionBuffer; let mut buffer = RegionBuffer::new();

buffer.push(1); buffer.push(2);

assert_eq!(buffer.len(), 2);

let mut a = buffer.getmut(0); let mut b = buffer.getmut(1);

asserteq!(*a, 1); asserteq!(*b, 2);

*a = *b; *b = 3;

asserteq!(*a, 2); asserteq!(*b, 3); There is a `region_buffer` macro provided to make initialisation more convenient. #[macrouse] extern crate regionbuffer;

fn main() { let strings = region_buffer!["Hello", "World", "!"];

let mut greeting = strings.getmut(0); let mut noun = strings.getmut(1); let mut punctuation = strings.get_mut(2);

*greeting = "Hallo"; *noun = "Peter"; *punctuation = ".";

let string = format!("{} {}{}", greeting, noun, punctuation); asserteq!(string, "Hallo Peter.") } The macro can also be used to specify and initialise large regions of memory. #[macrouse] extern crate region_buffer;

type Slice<'a> = region_buffer::Slice<'a, u8>;

struct Console; impl Console { fn new(_: Slice, _: Slice, _: Slice, _: Slice) {} }

fn main() { let memory = region_buffer![0; 0xFFFF];

let rom = memory.region(0, 0x800); let gpu = memory.region(0x800, 0x1600); let sound = memory.region(0x1600, 0x2400); let ram = memory.region(0x2400, 0xFFFF);

let console = Console::new(rom, gpu, sound, ram); } ```