Skip to main content

StdfWriter

Struct StdfWriter 

Source
pub struct StdfWriter<W> { /* private fields */ }
Expand description

STDF Writer

This writer accepts streams that implement Write trait, and writes STDF records in given byte order.

Multiple APIs are provided to write STDF records, including:

  • write_record for writing parsed STDF V4-2007 records, not including reserved/unknown records.
  • write_stdf_record for writing any parsed STDF records.
  • write_stdf_record_view for writing any STDF record views.
  • write_raw for writing any unprocessed STDF records.
  • write_raw_view for writing any unprocessed STDF record views.
use rust_stdf::{stdf_file::StdfWriter, ByteOrder, FAR};

let mut far = FAR::new();
far.cpu_type = 2;
far.stdf_ver = 4;

let mut out = Vec::new();
let mut writer = StdfWriter::new(&mut out, ByteOrder::LittleEndian);
writer.write_record(&far).unwrap();

assert_eq!(out, [2, 0, 0, 10, 2, 4]);

Implementations§

Source§

impl<W: Write> StdfWriter<W>

Source

pub fn new(writer: W, byte_order: ByteOrder) -> Self

Create a new writer with the given output stream and byte order.

Source

pub fn write_record<R: StdfRecordWrite>( &mut self, r: &R, ) -> Result<(), StdfError>

Write a STDF V4-2007 record to the output stream.

Validation will be performed on the record before writing, such as length check of Cn field, count check for Kx* fields, returns StdfError if validation fails.

Note: ReservedRec and UnknownRec cannot be written with this method, use write_stdf_record instead.

Source

pub fn write_stdf_record(&mut self, r: &StdfRecord) -> Result<(), StdfError>

Write a STDF V4-2007 record to the output stream, also supports ReservedRec and UnknownRec.

Validation will be performed on the record before writing.

Note: reserved/unknown record must match the writer’s byte order, otherwise, error StdfErrorKind::ByteOrderMismatch is returned.

Source

pub fn write_stdf_record_view( &mut self, v: &StdfRecordView<'_>, ) -> Result<(), StdfError>

Similar to write_stdf_record, but takes a borrowed StdfRecordView.

If known record types have different byte order than the writer, they are re-encoded via implicit to_owned(). Reserved/unknown views cannot be re-encoded, so a byte order mismatch returns error StdfErrorKind::ByteOrderMismatch.

Source

pub fn write_raw(&mut self, raw: &RawDataElement) -> Result<(), StdfError>

Write an unprocessed record RawDataElement to the output stream.

Byte order of the raw record must match the writer’s.

Source

pub fn write_raw_view( &mut self, v: &RawDataElementView<'_>, ) -> Result<(), StdfError>

Write an unprocessed record view RawDataElementView to the output stream.

Byte order of the raw record must match the writer’s.

Source

pub fn flush(&mut self) -> Result<(), StdfError>

Manually flush any buffered data to the output stream.

StdfWriter never buffers internally, but a wrapping BufWriter does; use this method to force wrapped writers to flush.

Auto Trait Implementations§

§

impl<W> Freeze for StdfWriter<W>
where W: Freeze,

§

impl<W> RefUnwindSafe for StdfWriter<W>
where W: RefUnwindSafe,

§

impl<W> Send for StdfWriter<W>
where W: Send,

§

impl<W> Sync for StdfWriter<W>
where W: Sync,

§

impl<W> Unpin for StdfWriter<W>
where W: Unpin,

§

impl<W> UnsafeUnpin for StdfWriter<W>
where W: UnsafeUnpin,

§

impl<W> UnwindSafe for StdfWriter<W>
where W: UnwindSafe,

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 = !

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

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

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.