pub struct StringFile<'a> { /* private fields */ }Expand description
FILE* wrapper over a string.
The last byte of the buffer is always reserved for a null character, which is only written by
StringFile::take.
Implementations§
Source§impl<'a> StringFile<'a>
impl<'a> StringFile<'a>
Sourcepub fn take(self) -> &'a mut [u8] ⓘ
pub fn take(self) -> &'a mut [u8] ⓘ
Adds a null character at the end of the current buffer and returns a view into the written section.
Sourcepub fn write(&mut self, bytes: &[u8]) -> usize
pub fn write(&mut self, bytes: &[u8]) -> usize
Returns bytes.len() and writes as much of bytes as it would fit in the buffer
[offset, size - 1) while reserving the last byte for null character.
Sourcepub fn used_region(&self) -> &[u8]
pub fn used_region(&self) -> &[u8]
Returns a region representing the currently used portion of the buffer.
Sourcepub fn available_region(&mut self) -> &mut [u8] ⓘ
pub fn available_region(&mut self) -> &mut [u8] ⓘ
Returns a region representing the remaining unused space in the buffer, not including the space reserved for the final null character.
Sourcepub fn skip(&mut self, amount: usize)
pub fn skip(&mut self, amount: usize)
Skip up to amount bytes in the buffer, advancing the write pointer as if we had written
data, but without actually changing the buffer.
Sourcepub fn as_bytes(&self) -> &[u8]
pub fn as_bytes(&self) -> &[u8]
Returns the currently used portion of the buffer, like C++ as_string_view().
Sourcepub fn with_file<R>(
&mut self,
f: impl for<'f> FnOnce(&mut ScopedFile<'f>) -> R,
) -> R
pub fn with_file<R>( &mut self, f: impl for<'f> FnOnce(&mut ScopedFile<'f>) -> R, ) -> R
Calls f with a C++-compatible FILE whose output is written into this StringFile.
This lets C++ routines that render into a FILE* write into a Rust StringFile.