Struct windowed_infinity::WindowedInfinity
source · pub struct WindowedInfinity<'a> { /* private fields */ }Expand description
A WindowedInfinity represents an infinite writable space. A small section of it is mapped to a &mut u8 to which writes are forwarded; writes to the area outside only advance a cursor.
The set of traits it implements depends on the configured cargo features:
- With the
stdfeature, it implements std::io::Write - With the
with_serde_cborfeature, it uses serde_cbor’s trait unsealing feature to implement its Write trait.
Implementations§
source§impl<'a> WindowedInfinity<'a>
impl<'a> WindowedInfinity<'a>
sourcepub fn new(view: &'a mut [u8], cursor: isize) -> Self
pub fn new(view: &'a mut [u8], cursor: isize) -> Self
Create a new infinity with the window passed as view. The cursor parameter indicates where (in the index space of the view) the infinity’s write operations should start, and is typically either 0 or negative.
sourcepub fn get_cursor(&self) -> isize
pub fn get_cursor(&self) -> isize
Report the current write cursor position in the index space of the view.
This typically used at the end of an infinity’s life time to see whether the view needs to be truncated before further processing, and whether there was any data discarded after the view.
sourcepub fn write(&mut self, data: &[u8])
pub fn write(&mut self, data: &[u8])
At the current cursor position, insert the given data.
The operation is always successful, and at least changes the write cursor.
sourcepub fn get_written(&self) -> &[u8]
pub fn get_written(&self) -> &[u8]
Obtain the written content inside the window, if any.
The slices could be made to have a longer lifetime if there is demand for that by using the
sealingslice crate.