[][src]Module kernel::common::leasable_buffer

Defines a LeasableBuffer type which can be used to pass a section of a larger buffer but still get the entire buffer back in a callback

Author: Amit Levy

Usage

slice() is used to set the portion of the LeasableBuffer that is accessbile. reset() makes the entire LeasableBuffer accessible again. Typically, slice() will be called prior to passing the buffer down to lower layers, and reset() will be called once the LeasableBuffer is returned via a callback


let mut internal = ['a', 'b', 'c', 'd'];
let original_base_addr = internal.as_ptr();

let mut buffer = LeasableBuffer::new(&mut internal);

buffer.slice(1..3);

assert_eq!(buffer.as_ptr(), unsafe { original_base_addr.offset(1) });
assert_eq!(buffer.len(), 2);
assert_eq!((buffer[0], buffer[1]), ('b', 'c'));

buffer.reset();

assert_eq!(buffer.as_ptr(), original_base_addr);
assert_eq!(buffer.len(), 4);
assert_eq!((buffer[0], buffer[1]), ('a', 'b'));

Structs

LeasableBuffer

Leasable Buffer which can be used to pass a section of a larger buffer but still get the entire buffer back in a callback