Enum StdfRecord

Source
pub enum StdfRecord {
Show 34 variants FAR(FAR), ATR(ATR), VUR(VUR), MIR(MIR), MRR(MRR), PCR(PCR), HBR(HBR), SBR(SBR), PMR(PMR), PGR(PGR), PLR(PLR), RDR(RDR), SDR(SDR), PSR(PSR), NMR(NMR), CNR(CNR), SSR(SSR), CDR(CDR), WIR(WIR), WRR(WRR), WCR(WCR), PIR(PIR), PRR(PRR), TSR(TSR), PTR(PTR), MPR(MPR), FTR(FTR), STR(STR), BPS(BPS), EPS(EPS), GDR(GDR), DTR(DTR), ReservedRec(ReservedRec), InvalidRec(RecordHeader),
}
Expand description

StdfRecord is the data that returned from StdfReader iterator.

it contains the actually structs that contain STDF data.

use match structure to access the nested data.

§Example

use rust_stdf::{StdfRecord, stdf_record_type::*};

let mut rec = StdfRecord::new(REC_PTR);
if let StdfRecord::PTR(ref mut ptr_data) = rec {
    ptr_data.result = 100.0;
}
println!("{:?}", rec);

Variants§

§

FAR(FAR)

§

ATR(ATR)

§

VUR(VUR)

§

MIR(MIR)

§

MRR(MRR)

§

PCR(PCR)

§

HBR(HBR)

§

SBR(SBR)

§

PMR(PMR)

§

PGR(PGR)

§

PLR(PLR)

§

RDR(RDR)

§

SDR(SDR)

§

PSR(PSR)

§

NMR(NMR)

§

CNR(CNR)

§

SSR(SSR)

§

CDR(CDR)

§

WIR(WIR)

§

WRR(WRR)

§

WCR(WCR)

§

PIR(PIR)

§

PRR(PRR)

§

TSR(TSR)

§

PTR(PTR)

§

MPR(MPR)

§

FTR(FTR)

§

STR(STR)

§

BPS(BPS)

§

EPS(EPS)

§

GDR(GDR)

§

DTR(DTR)

§

ReservedRec(ReservedRec)

§

InvalidRec(RecordHeader)

Implementations§

Source§

impl StdfRecord

Source

pub fn new(rec_type: u64) -> Self

Create a StdfRecord of a given type with default data

use rust_stdf::{StdfRecord, stdf_record_type::REC_PMR};

// create StdfRecord with a nested PMR
let new_rec = StdfRecord::new(REC_PMR);

if let StdfRecord::PMR(pmr_rec) = new_rec {
    assert_eq!(pmr_rec.head_num, 1);
    assert_eq!(pmr_rec.site_num, 1);
} else {
    // this case will not be hit
}
Source

pub fn new_from_header(header: RecordHeader) -> Self

Create a StdfRecord from a RecordHeader with default data

The difference between new() is that this method can save the info of an invalid record header, help the caller to debug

use rust_stdf::{StdfRecord, RecordHeader, stdf_record_type::REC_PMR};

// create a PMR StdfRecord from header
// (1, 60)
let pmr_header = RecordHeader {typ: 1, sub: 60, len: 0 };
let new_rec = StdfRecord::new_from_header(pmr_header);

if let StdfRecord::PMR(pmr_rec) = new_rec {
    assert_eq!(pmr_rec.head_num, 1);
    assert_eq!(pmr_rec.site_num, 1);
} else {
    // this case will not be hit
}
Source

pub fn get_type(&self) -> u64

returns the record type cdoe of the given StdfRecord, which is defined in rust_stdf::stdf_record_type::* module.

use rust_stdf::{StdfRecord, stdf_record_type::*};

// `REC_PTR` type code can be used for creating a new StdfRecord
let new_rec = StdfRecord::new(REC_PTR);
let returned_code = new_rec.get_type();

assert_eq!(REC_PTR, returned_code);

// type code can be used in variety of functions
// get record (typ, sub)
assert_eq!((15, 10), get_typ_sub_from_code(returned_code).unwrap());
// get record name
assert_eq!("PTR", get_rec_name_from_code(returned_code));
Source

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

check the StdfRecord belongs the given type code(s), it is useful for filtering the records during the parsing iteration.

use rust_stdf::{StdfRecord, stdf_record_type::*};

let new_rec = StdfRecord::new(REC_PTR);

assert!(new_rec.is_type(REC_PTR));
assert!(new_rec.is_type(REC_PTR | REC_FTR | REC_MPR));
assert!(!new_rec.is_type(REC_FTR | REC_MPR));
Source

pub fn read_from_bytes(&mut self, raw_data: &[u8], order: &ByteOrder)

parse StdfRecord from byte data which DOES NOT contain the record header (len, typ, sub),

requires a mutable StdfRecord to store the parsed data

use rust_stdf::{StdfRecord, ByteOrder, stdf_record_type::*};

let raw_with_no_header: [u8; 2] = [1, 4];
let mut new_rec = StdfRecord::new(REC_FAR);
new_rec.read_from_bytes(&raw_with_no_header, &ByteOrder::LittleEndian);

if let StdfRecord::FAR(ref far_rec) = new_rec {
    assert_eq!(4, far_rec.stdf_ver);
}
Source

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

parse StdfRecord from byte data which contains the record header (len, typ, sub).

§Error

if the input data is not a valid (wrong typ, sub), incomplete data or incorrect byte order, StdfError will be returned instead.

use rust_stdf::{StdfRecord, ByteOrder, stdf_record_type::*};

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

if let StdfRecord::FAR(far_rec) = new_rec {
    assert_eq!(4, far_rec.stdf_ver);
}

Trait Implementations§

Source§

impl Clone for StdfRecord

Source§

fn clone(&self) -> StdfRecord

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for StdfRecord

Source§

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

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

impl From<&RawDataElement> for StdfRecord

Source§

fn from(raw_element: &RawDataElement) -> Self

it will NOT consume the input RawDataElement

Source§

impl From<RawDataElement> for StdfRecord

Source§

fn from(raw_element: RawDataElement) -> Self

it will consume the input RawDataElement

Source§

impl PartialEq for StdfRecord

Source§

fn eq(&self, other: &StdfRecord) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for StdfRecord

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