Struct savefile::Serializer

source ·
pub struct Serializer<'a, W: Write> {
    pub writer: &'a mut W,
    pub version: u32,
}
Expand description

Object to which serialized data is to be written. This is basically just a wrapped std::io::Write object and a file protocol version number. In versions prior to 0.15, ‘Serializer’ did not accept a type parameter. It now requires a type parameter with the type of writer to operate on.

Fields§

§writer: &'a mut W

The underlying writer. You should not access this.

§version: u32

The version of the data structures in memory which are being serialized.

Implementations§

source§

impl<'a, W: Write + 'a> Serializer<'a, W>

source

pub fn write_bool(&mut self, v: bool) -> Result<(), SavefileError>

Writes a binary bool to the output

source

pub fn write_u8(&mut self, v: u8) -> Result<(), SavefileError>

Writes a binary u8 to the output

source

pub fn write_i8(&mut self, v: i8) -> Result<(), SavefileError>

Writes a binary i8 to the output

source

pub fn write_u16(&mut self, v: u16) -> Result<(), SavefileError>

Writes a binary little endian u16 to the output

source

pub fn write_i16(&mut self, v: i16) -> Result<(), SavefileError>

Writes a binary little endian i16 to the output

source

pub fn write_u32(&mut self, v: u32) -> Result<(), SavefileError>

Writes a binary little endian u32 to the output

source

pub fn write_i32(&mut self, v: i32) -> Result<(), SavefileError>

Writes a binary little endian i32 to the output

source

pub fn write_f32(&mut self, v: f32) -> Result<(), SavefileError>

Writes a binary little endian f32 to the output

source

pub fn write_f64(&mut self, v: f64) -> Result<(), SavefileError>

Writes a binary little endian f64 to the output

source

pub fn write_u64(&mut self, v: u64) -> Result<(), SavefileError>

Writes a binary little endian u64 to the output

source

pub fn write_i64(&mut self, v: i64) -> Result<(), SavefileError>

Writes a binary little endian i64 to the output

source

pub fn write_u128(&mut self, v: u128) -> Result<(), SavefileError>

Writes a binary little endian u128 to the output

source

pub fn write_i128(&mut self, v: i128) -> Result<(), SavefileError>

Writes a binary little endian i128 to the output

source

pub fn write_usize(&mut self, v: usize) -> Result<(), SavefileError>

Writes a binary little endian usize as u64 to the output

source

pub fn write_isize(&mut self, v: isize) -> Result<(), SavefileError>

Writes a binary little endian isize as i64 to the output

source

pub fn write_buf(&mut self, v: &[u8]) -> Result<(), SavefileError>

Writes a binary u8 array to the output

source

pub fn write_string(&mut self, v: &str) -> Result<(), SavefileError>

Writes as a string as 64 bit length + utf8 data

source

pub fn write_bytes(&mut self, v: &[u8]) -> Result<(), SavefileError>

Writes a binary u8 array to the output. Synonym of write_buf.

source

pub fn save<T: WithSchema + Serialize>( writer: &mut W, version: u32, data: &T, with_compression: bool ) -> Result<(), SavefileError>

Creata a new serializer. Don’t use this function directly, use the crate::save function instead.

source

pub fn save_noschema<T: WithSchema + Serialize>( writer: &mut W, version: u32, data: &T ) -> Result<(), SavefileError>

Creata a new serializer. Don’t use this function directly, use the crate::save_noschema function instead.

source

pub fn new_raw(writer: &mut impl Write) -> Serializer<'_, impl Write>

Create a Serializer. Don’t use this method directly, use the crate::save function instead.

Auto Trait Implementations§

§

impl<'a, W> RefUnwindSafe for Serializer<'a, W>
where W: RefUnwindSafe,

§

impl<'a, W> Send for Serializer<'a, W>
where W: Send,

§

impl<'a, W> Sync for Serializer<'a, W>
where W: Sync,

§

impl<'a, W> Unpin for Serializer<'a, W>

§

impl<'a, W> !UnwindSafe for Serializer<'a, W>

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

§

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

§

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.