Skip to main content

Writer

Struct Writer 

Source
pub struct Writer {
    pub data: Vec<u8>,
    pub wide_strings: bool,
    /* private fields */
}
Expand description

The writing side of Reader (IO::BinaryWriter): little-endian values, 8-bit strings and blocks whose size is filled in when they close.

Fields§

§data: Vec<u8>

The bytes written.

§wide_strings: bool

Write System::Strings as UTF-16 (as older builds did) instead of 8-bit.

Implementations§

Source§

impl Writer

Source

pub fn new() -> Self

An empty writer.

Source

pub fn set_reference_ids(&mut self, ids: &BTreeMap<u32, String>)

Write external pointers as reference ids (the inverse of the reference table).

Source

pub fn bytes(&mut self, b: &[u8])

Write bytes as they are.

Source

pub fn u8(&mut self, v: u8)

Write a u8.

Source

pub fn bool(&mut self, v: bool)

Write a bool as one byte.

Source

pub fn i16(&mut self, v: i16)

Write an i16.

Source

pub fn u16(&mut self, v: u16)

Write a u16.

Source

pub fn u32(&mut self, v: u32)

Write a u32.

Source

pub fn i32(&mut self, v: i32)

Write an i32.

Source

pub fn i64(&mut self, v: i64)

Write an i64.

Source

pub fn f32(&mut self, v: f32)

Write an f32.

Source

pub fn count(&mut self, n: usize)

A count as the reader’s count takes it.

Source

pub fn string(&mut self, s: &str)

System::String with the 8-bit flag (or UTF-16 with Writer::wide_strings); the length counts the NUL.

Source

pub fn wstring(&mut self, s: &str)

A UTF-16 string: the unit count with its NUL, then the units.

Source

pub fn external_ref(&mut self, path: Option<&str>) -> Result<()>

ExternalPtr, in reference mode an id (u32::MAX for none), else a present flag and the path.

Source

pub fn begin_block(&mut self, version: u32) -> usize

Open a block at version; returns where its size goes, for Writer::end_block.

Source

pub fn end_block(&mut self, size_at: usize)

Close the block opened at size_at. The size covers the payload and terminator, not the version.

Source

pub fn block<T>( &mut self, version: u32, f: impl FnOnce(&mut Self) -> Result<T>, ) -> Result<T>

One block at version, its payload written by f.

Trait Implementations§

Source§

impl Default for Writer

Source§

fn default() -> Writer

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.