Add casting function for coral::fixed_buffer to coral::slice

This commit is contained in:
kayomn 2023-02-22 23:29:33 +00:00
parent 2dd7946b88
commit c3a49eed7f
1 changed files with 10 additions and 0 deletions

View File

@ -10,6 +10,16 @@ export namespace coral {
template<usize capacity> struct fixed_buffer : public writer, public reader { template<usize capacity> struct fixed_buffer : public writer, public reader {
fixed_buffer(coral::u8 fill_value) : data{fill_value} {} fixed_buffer(coral::u8 fill_value) : data{fill_value} {}
/**
* Returns a mutable [slice] ranging from the head to the last-filled element.
*
* *Note*: The lifetime and validity of the returned slice is only guaranteed for as long
* as the source [fixed_buffer] is not mutated or out-of-scope.
*/
slice<u8 const> as_slice() const {
return {0, this->filled};
}
/** /**
* Returns the base pointer of the buffer data. * Returns the base pointer of the buffer data.
*/ */