From c3a49eed7ff87068949e725e15b4bea70f9ad87f Mon Sep 17 00:00:00 2001 From: kayomn Date: Wed, 22 Feb 2023 23:29:33 +0000 Subject: [PATCH] Add casting function for coral::fixed_buffer to coral::slice --- source/coral/io.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/source/coral/io.cpp b/source/coral/io.cpp index 07e1bd8..8a357e6 100644 --- a/source/coral/io.cpp +++ b/source/coral/io.cpp @@ -10,6 +10,16 @@ export namespace coral { template struct fixed_buffer : public writer, public reader { 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 as_slice() const { + return {0, this->filled}; + } + /** * Returns the base pointer of the buffer data. */