Skip to main content

StdfRecordView

Enum StdfRecordView 

Source
pub enum StdfRecordView<'a> {
Show 34 variants FAR(FARView<'a>), ATR(ATRView<'a>), VUR(VURView<'a>), MIR(MIRView<'a>), MRR(MRRView<'a>), PCR(PCRView<'a>), HBR(HBRView<'a>), SBR(SBRView<'a>), PMR(PMRView<'a>), PGR(PGRView<'a>), PLR(PLRView<'a>), RDR(RDRView<'a>), SDR(SDRView<'a>), PSR(PSRView<'a>), NMR(NMRView<'a>), CNR(CNRView<'a>), SSR(SSRView<'a>), CDR(CDRView<'a>), WIR(WIRView<'a>), WRR(WRRView<'a>), WCR(WCRView<'a>), PIR(PIRView<'a>), PRR(PRRView<'a>), TSR(TSRView<'a>), PTR(PTRView<'a>), MPR(MPRView<'a>), FTR(FTRView<'a>), STR(STRView<'a>), BPS(BPSView<'a>), EPS, GDR(GDRView<'a>), DTR(DTRView<'a>), ReservedRec(ReservedRecView<'a>), UnknownRec(ReservedRecView<'a>),
}
Expand description

Zero-copy view over the field data of a single STDF record.

Unlike StdfRecord, which eagerly parses every field into owned values, a StdfRecordView only records each field’s byte offset and reads a field on demand. It borrows the raw bytes it was built from and never allocates for scalar fields.

A view can be built from:

  1. A borrowed RawDataElement (From<&RawDataElement>),
  2. A header plus raw field data (StdfRecordView::read_from_bytes).
  3. A buffer that includes the 4-byte record header and the raw field data (StdfRecordView::read_from_bytes_with_header).

Variants§

§

FAR(FARView<'a>)

§

ATR(ATRView<'a>)

§

VUR(VURView<'a>)

§

MIR(MIRView<'a>)

§

MRR(MRRView<'a>)

§

PCR(PCRView<'a>)

§

HBR(HBRView<'a>)

§

SBR(SBRView<'a>)

§

PMR(PMRView<'a>)

§

PGR(PGRView<'a>)

§

PLR(PLRView<'a>)

§

RDR(RDRView<'a>)

§

SDR(SDRView<'a>)

§

PSR(PSRView<'a>)

§

NMR(NMRView<'a>)

§

CNR(CNRView<'a>)

§

SSR(SSRView<'a>)

§

CDR(CDRView<'a>)

§

WIR(WIRView<'a>)

§

WRR(WRRView<'a>)

§

WCR(WCRView<'a>)

§

PIR(PIRView<'a>)

§

PRR(PRRView<'a>)

§

TSR(TSRView<'a>)

§

PTR(PTRView<'a>)

§

MPR(MPRView<'a>)

§

FTR(FTRView<'a>)

§

STR(STRView<'a>)

§

BPS(BPSView<'a>)

§

EPS

§

GDR(GDRView<'a>)

§

DTR(DTRView<'a>)

§

ReservedRec(ReservedRecView<'a>)

§

UnknownRec(ReservedRecView<'a>)

Implementations§

Source§

impl<'a> StdfRecordView<'a>

Source

pub fn read_from_bytes( header: RecordHeader, raw_data: &'a [u8], byte_order: &ByteOrder, ) -> Self

Build a view from RecordHeader, raw field data and byte order.

use rust_stdf::{StdfRecordView, ByteOrder, RecordHeader, stdf_record_type::REC_PTR};

let header = RecordHeader { len: 0, typ: 15, sub: 10 }; // PTR
let raw: [u8; 0] = []; // empty field data; getters fall back to defaults
let view = StdfRecordView::read_from_bytes(header, &raw, &ByteOrder::LittleEndian);

if let StdfRecordView::PTR(ptr_view) = view {
    assert_eq!(0, ptr_view.test_num());
}
assert!(view.is_type(REC_PTR));
Source

pub fn read_from_bytes_with_header( raw_data: &'a [u8], order: &ByteOrder, ) -> Result<Self, StdfError>

Parse a StdfRecordView from byte data that contains the record header (len, typ, sub).

§Error

Returns StdfError when the input is not a valid header or is incomplete (the buffer is shorter than the header declares).

use rust_stdf::{StdfRecordView, ByteOrder};

let raw_with_header: [u8; 6] = [0, 2, 0, 10, 1, 4];
let view = StdfRecordView::read_from_bytes_with_header(
    &raw_with_header,
    &ByteOrder::BigEndian,
).unwrap();

if let StdfRecordView::FAR(far_view) = view {
    assert_eq!(4, far_view.stdf_ver());
}
Source

pub fn get_type(&self) -> u64

Return the record type code (see stdf_record_type::*).

Source

pub fn is_type(&self, rec_type: u64) -> bool

Check whether this view belongs to the given record type(s).

Source

pub fn to_owned(&self) -> StdfRecord

Parse this borrowed view into an owned StdfRecord, escaping the borrow of the underlying buffer.

Trait Implementations§

Source§

impl<'a> Clone for StdfRecordView<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for StdfRecordView<'a>

Source§

impl<'a> Debug for StdfRecordView<'a>

Source§

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

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

impl<'a> From<&'a RawDataElement> for StdfRecordView<'a>

Source§

fn from(raw_element: &'a RawDataElement) -> Self

Build a zero-copy view; does not consume the input.

Source§

impl<'a> From<&RawDataElementView<'a>> for StdfRecordView<'a>

Source§

fn from(raw_view: &RawDataElementView<'a>) -> Self

Build a zero-copy view; does not consume the input.

Source§

impl<'a> From<&StdfRecordView<'a>> for StdfRecord

Source§

fn from(view: &StdfRecordView<'a>) -> Self

Parse the borrowed view into an owned record; does not consume the view.

Auto Trait Implementations§

§

impl<'a> Freeze for StdfRecordView<'a>

§

impl<'a> RefUnwindSafe for StdfRecordView<'a>

§

impl<'a> Send for StdfRecordView<'a>

§

impl<'a> Sync for StdfRecordView<'a>

§

impl<'a> Unpin for StdfRecordView<'a>

§

impl<'a> UnsafeUnpin for StdfRecordView<'a>

§

impl<'a> UnwindSafe for StdfRecordView<'a>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.