Skip to main content

StringFile

Struct StringFile 

Source
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>

Source

pub fn new(buffer: &'a mut [u8]) -> Self

Creates a StringFile that writes into buffer.

Source

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.

Source

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.

Source

pub fn used_region(&self) -> &[u8]

Returns a region representing the currently used portion of the buffer.

Source

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.

Source

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.

Source

pub fn as_bytes(&self) -> &[u8]

Returns the currently used portion of the buffer, like C++ as_string_view().

Source

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.

Trait Implementations§

Source§

impl AsRef<[u8]> for StringFile<'_>

Source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'a> Debug for StringFile<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Write for StringFile<'_>

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a [char] into this writer, returning whether the write succeeded. Read more
1.0.0§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the [write!] macro with implementors of this trait. Read more

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for StringFile<'a>

§

impl<'a> Freeze for StringFile<'a>

§

impl<'a> RefUnwindSafe for StringFile<'a>

§

impl<'a> Send for StringFile<'a>

§

impl<'a> Sync for StringFile<'a>

§

impl<'a> Unpin for StringFile<'a>

§

impl<'a> UnsafeUnpin for StringFile<'a>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = !

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.