[][src]Crate region_buffer

region_buffer

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

Examples

let mut buffer = RegionBuffer::new();

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

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

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

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

*a = *b;
*b = 3;

assert_eq!(*a, 2);
assert_eq!(*b, 3);

There is a region_buffer macro provided to make initialisation more convenient.


let strings = region_buffer!["Hello", "World", "!"];

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

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

let string = format!("{} {}{}", greeting, noun, punctuation);
assert_eq!(string, "Hallo Peter.")

The macro can also be used to specify and initialise large regions of memory.

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

Macros

region_buffer

Creates a RegionBuffer containing the arguments. region_buffer! allows RegionBuffers to be defined with the same syntax as array expressions. There are two forms of this macro:

Structs

Element

A struct representing a single element from the RegionBuffer. When Dropped the element's solitary region is freed.

ElementMut

A struct representing a single mutable element from the RegionBuffer. When Dropped the element's solitary region is freed.

RegionBuffer

A contiguous growable array type, allow you to obtain multiple mutable regions from it, as long these regions don't overlap.

Slice

Represents a mutable slice into a region of memory. The region will be freed on Drop.