### Install rust-stdf with Cargo Source: https://context7.com/noonchen/rust-stdf/llms.txt Demonstrates how to add the rust-stdf library to your project's Cargo.toml file. You can use default features (gzip and bzip compression) or customize specific features like compression, serialization, and ATDF support. ```toml [dependencies] rust-stdf = "0.3.1" ``` ```toml [dependencies] rust-stdf = { version = "0.3.1", default-features = false, features = ["gzip", "bzip", "serialize", "atdf"] } ``` -------------------------------- ### Create STDF Reader from Custom Stream with StdfReader::from Source: https://context7.com/noonchen/rust-stdf/llms.txt This Rust example demonstrates creating an `StdfReader` from a custom input stream that implements `BufRead` and `Seek`. It allows for explicit specification of the compression type, offering more control over input sources beyond simple file paths. The code then processes MIR records to extract lot and part information. ```rust use rust_stdf::{stdf_file::*, stdf_record_type::*, StdfRecord, CompressType}; use std::io::BufReader; use std::fs::File; fn main() { // Open file manually and create buffered reader let file = File::open("demo_stdf/lot3.stdf").unwrap(); let buf_reader = BufReader::with_capacity(2 << 20, file); // Create reader with explicit compression type let mut reader = StdfReader::from(buf_reader, &CompressType::Uncompressed) .expect("Failed to create STDF reader"); // Process all MIR (Master Information Record) entries for rec in reader .get_record_iter() .filter_map(|x| x.ok()) .filter(|x| x.is_type(REC_MIR)) { if let StdfRecord::MIR(mir) = rec { println!("Lot ID: {}", mir.lot_id); println!("Part Type: {}", mir.part_typ); println!("Job Name: {}", mir.job_nam); println!("Tester Type: {}", mir.tstr_typ); } } } ``` -------------------------------- ### Access Unprocessed STDF Data with get_rawdata_iter Source: https://context7.com/noonchen/rust-stdf/llms.txt This Rust code snippet illustrates how to use `get_rawdata_iter` to obtain an iterator over `RawDataElement` structs. These elements contain the raw, unparsed STDF bytes along with offset information. The example filters for PTR records, prints raw data details, and then converts a raw element into a parsed `StdfRecord` for further inspection. ```rust use rust_stdf::{stdf_file::*, stdf_record_type::*, StdfRecord, RawDataElement}; fn main() { let mut reader = StdfReader::new("demo_stdf/lot2.stdf").unwrap(); // Iterate raw data elements for PTR records only let rec_types = REC_PTR; for raw in reader .get_rawdata_iter() .map(|x| x.unwrap()) .filter(|x| x.is_type(rec_types)) { // Access raw data properties println!("Offset: {}, Record Type: ({}, {}), Data length: {}", raw.offset, raw.header.typ, raw.header.sub, raw.raw_data.len() ); // Convert raw element to parsed StdfRecord when needed let parsed_record: StdfRecord = raw.into(); if let StdfRecord::PTR(ptr) = parsed_record { println!(" Test #{}: result = {}", ptr.test_num, ptr.result); } } } ``` -------------------------------- ### Serializing STDF Records to JSON with Serde in Rust Source: https://context7.com/noonchen/rust-stdf/llms.txt Demonstrates how to serialize STDF records to JSON format using the Serde library in Rust. It shows how to read STDF files, iterate through records, convert specific record types (like PTR and MIR) to JSON values, and access field names for a given record type. Requires the 'serialize' feature. ```rust // Requires: features = ["serialize"] use rust_stdf::{stdf_file::*, stdf_record_type::*, StdfRecord, PTR}; use serde_json; fn main() { let mut reader = StdfReader::new("demo_stdf/lot2.stdf").unwrap(); for stdf_rec in reader.get_record_iter().filter_map(|x| x.ok()) { match stdf_rec { StdfRecord::PTR(ptr) => { // Serialize to JSON let json = serde_json::to_value(&ptr).unwrap(); println!("{}", serde_json::to_string_pretty(&json).unwrap()); // Access field names array for field in PTR::FIELD_NAMES_AS_ARRAY { println!("Field: {}, Value: {}", field, json[field]); } } StdfRecord::MIR(mir) => { let json = serde_json::to_string(&mir).unwrap(); println!("MIR JSON: {}", json); } _ => {} } } } ``` -------------------------------- ### Parsing ATDF Files with AtdfReader in Rust Source: https://context7.com/noonchen/rust-stdf/llms.txt Shows how to use the `AtdfReader` in Rust to parse ATDF (ASCII Test Data Format) files. It covers opening files (including compressed variants like .gz and .bz2) and iterating through records to convert them back to ATDF string format. Requires the 'atdf' feature. ```rust // Requires: features = ["atdf"] use rust_stdf::atdf_file::*; fn main() { // Open ATDF file (supports .atdf, .atdf.gz, .atdf.bz2) let atdf_path = "test_data.atdf"; let mut reader = match AtdfReader::new(&atdf_path) { Ok(r) => r, Err(e) => { println!("Failed to open ATDF file: {}", e); return; } }; // Iterate through ATDF records for rec in reader.get_record_iter() { // Convert record back to ATDF string format println!("{}", rec.to_atdf_string()); } } ``` -------------------------------- ### Open and Parse STDF Files with StdfReader::new Source: https://context7.com/noonchen/rust-stdf/llms.txt This Rust code snippet shows how to create an `StdfReader` instance from a file path. The reader automatically handles common compression formats (.gz, .bz2, .zip) and detects byte order from the STDF header. It then iterates through records, filtering for specific types (PIR and PTR) to count DUTs and collect continuity test results. ```rust use rust_stdf::{stdf_file::*, stdf_record_type::*, StdfRecord}; fn main() { // Open STDF file (supports .stdf, .stdf.gz, .stdf.bz2, .zip) let stdf_path = "demo_stdf/lot2.stdf"; let mut reader = match StdfReader::new(&stdf_path) { Ok(r) => r, Err(e) => { println!("Failed to open STDF file: {}", e); return; } }; // Count DUTs and collect specific test results let mut dut_count: u64 = 0; let mut continuity_results = vec![]; // Filter for specific record types using bitwise OR let rec_types = REC_PIR | REC_PTR; // Iterate through records with type filtering for rec in reader .get_record_iter() .map(|x| x.unwrap()) .filter(|x| x.is_type(rec_types)) { match rec { StdfRecord::PIR(_) => { dut_count += 1; } StdfRecord::PTR(ref ptr_rec) => { if ptr_rec.test_txt == "continuity test" { continuity_results.push(ptr_rec.result); } } _ => {} } } println!("Total DUTs: {}", dut_count); println!("Continuity test results: {:?}", continuity_results); // Output: Total DUTs: 25 // Output: Continuity test results: [0.5, 0.6, 0.55, ...] } ``` -------------------------------- ### Convert STDF to Excel with rust-stdf Serialization Source: https://context7.com/noonchen/rust-stdf/llms.txt Demonstrates converting STDF files to Excel spreadsheets using the serialize feature. Requires `rust_xlsxwriter` and `serde_json` dependencies, along with the 'serialize' feature for rust-stdf. It iterates through STDF records, counts them by type, and prints details for PTR, PRR, and HBR records. ```rust // Requires: features = ["serialize"] // Also requires: rust_xlsxwriter, serde_json dependencies use rust_stdf::{stdf_file::*, stdf_record_type::*, StdfRecord}; use std::collections::HashMap; fn main() { let mut reader = StdfReader::new("demo_stdf/lot2.stdf").unwrap(); // Track record counts by type let mut record_counts: HashMap<&str, u32> = HashMap::new(); for stdf_rec in reader.get_record_iter().filter_map(|x| x.ok()) { let rec_name = get_rec_name_from_code(stdf_rec.get_type()); *record_counts.entry(rec_name).or_insert(0) += 1; // Process specific record types match stdf_rec { StdfRecord::PTR(ptr) => { // Test number, result, limits, units println!("PTR: Test #{} '{}' = {} {}", ptr.test_num, ptr.test_txt, ptr.result, ptr.units.unwrap_or_default() ); } StdfRecord::PRR(prr) => { // Part result record println!("PRR: Part {} at ({}, {}) - HBin: {}, SBin: {}", prr.part_id, prr.x_coord, prr.y_coord, prr.hard_bin, prr.soft_bin ); } StdfRecord::HBR(hbr) => { // Hardware bin record println!("HBR: Bin {} '{}' - Count: {}, P/F: {}", hbr.hbin_num, hbr.hbin_nam, hbr.hbin_cnt, hbr.hbin_pf ); } _ => {} // Ignore other record types for this example } } // Print summary println!("\nRecord Summary:"); for (name, count) in &record_counts { println!(" {}: {} records", name, count); } } ``` -------------------------------- ### Working with Parsed STDF Records in Rust Source: https://context7.com/noonchen/rust-stdf/llms.txt Demonstrates how to create, modify, and parse STDF records using the StdfRecord enum in Rust. It shows pattern matching for data access, type checking with is_type(), and reading from raw bytes with and without headers. ```rust use rust_stdf::{StdfRecord, stdf_record_type::*, ByteOrder, RecordHeader}; fn main() { // Create a new record programmatically let mut ptr_record = StdfRecord::new(REC_PTR); // Modify record data via pattern matching if let StdfRecord::PTR(ref mut ptr) = ptr_record { ptr.test_num = 1001; ptr.result = 3.14159; ptr.test_txt = "Voltage Test".to_string(); ptr.head_num = 1; ptr.site_num = 1; } // Check record type assert!(ptr_record.is_type(REC_PTR)); assert!(ptr_record.is_type(REC_PTR | REC_FTR | REC_MPR)); assert!(!ptr_record.is_type(REC_FTR)); // Get record type code let type_code = ptr_record.get_type(); assert_eq!(type_code, REC_PTR); // Parse from raw bytes (without header) let raw_data: [u8; 2] = [1, 4]; // FAR record data let mut far_record = StdfRecord::new(REC_FAR); far_record.read_from_bytes(&raw_data, &ByteOrder::LittleEndian); if let StdfRecord::FAR(far) = far_record { println!("CPU Type: {}, STDF Version: {}", far.cpu_type, far.stdf_ver); // Output: CPU Type: 1, STDF Version: 4 } // Parse from raw bytes (with header) let raw_with_header: [u8; 6] = [0, 2, 0, 10, 1, 4]; // len=2, typ=0, sub=10 let parsed = StdfRecord::read_from_bytes_with_header( &raw_with_header, &ByteOrder::BigEndian ).unwrap(); assert!(parsed.is_type(REC_FAR)); } ``` -------------------------------- ### Control rust-stdf Features in Cargo.toml Source: https://github.com/noonchen/rust-stdf/blob/main/README.md Demonstrates how to explicitly control which features of the rust-stdf library are enabled. This is useful for optimizing build size or including specific functionalities like gzip or bzip compression. ```toml rust-stdf = { version="0.3.1", default-features = false, features = ["gzip", ...]} ``` -------------------------------- ### STDF Record Type Constants and Helpers in Rust Source: https://context7.com/noonchen/rust-stdf/llms.txt Explains the use of constants and helper functions from the `stdf_record_type` module in Rust for managing STDF record types. It covers combining type codes, converting between codes and (typ, sub) tuples, and retrieving record names. ```rust use rust_stdf::stdf_record_type::*; fn main() { // Record type constants can be combined with bitwise OR let test_records = REC_PTR | REC_MPR | REC_FTR | REC_STR; let wafer_records = REC_WIR | REC_WRR | REC_WCR; let part_records = REC_PIR | REC_PRR; // Convert type code to (typ, sub) tuple let ptr_typ_sub = get_typ_sub_from_code(REC_PTR).unwrap(); assert_eq!(ptr_typ_sub, (15, 10)); // Convert (typ, sub) to type code let type_code = get_code_from_typ_sub(15, 10); assert_eq!(type_code, REC_PTR); // Get record name string from type code let rec_name = get_rec_name_from_code(REC_PTR); assert_eq!(rec_name, "PTR"); // Get type code from record name let code = get_code_from_rec_name("PTR"); assert_eq!(code, REC_PTR); // All available record type constants: // Type 0: REC_FAR, REC_ATR, REC_VUR // Type 1: REC_MIR, REC_MRR, REC_PCR, REC_HBR, REC_SBR, REC_PMR, // REC_PGR, REC_PLR, REC_RDR, REC_SDR, REC_PSR, REC_NMR, // REC_CNR, REC_SSR, REC_CDR // Type 2: REC_WIR, REC_WRR, REC_WCR // Type 5: REC_PIR, REC_PRR // Type 10: REC_TSR // Type 15: REC_PTR, REC_MPR, REC_FTR, REC_STR // Type 20: REC_BPS, REC_EPS // Type 50: REC_GDR, REC_DTR // Special: REC_RESERVE, REC_INVALID } ``` -------------------------------- ### Handle STDF Parsing Errors with StdfError in Rust Source: https://context7.com/noonchen/rust-stdf/llms.txt Illustrates robust error handling for STDF file parsing using the `StdfError` type. It demonstrates handling file opening errors and iterating through records while managing potential parsing errors with specific error codes and messages. ```rust use rust_stdf::{stdf_file::*, StdfRecord}; fn main() { // Handle file opening errors let result = StdfReader::new("nonexistent.stdf"); match result { Ok(mut reader) => { // Process records, handling iteration errors for rec_result in reader.get_record_iter() { match rec_result { Ok(rec) => { println!("Record type: {}", rec.get_type()); } Err(e) => { // Error codes: // 1 = Invalid STDF File // 2 = Invalid Record Type // 3 = IO Error // 4 = EOF (normal end of file) // 5 = Unexpected EOF // 6 = Non-ASCII Found (ATDF) // 7 = Invalid ATDF File // 8 = Zip related error println!("Parse error (code {}): {}", e.code, e.msg); if e.code == 5 { println!("File appears to be truncated"); break; } } } } } Err(e) => { println!("Failed to open file: {}", e); } } } ``` -------------------------------- ### Iterate STDF Records in Rust Source: https://github.com/noonchen/rust-stdf/blob/main/README.md This Rust code snippet demonstrates how to read an STDF file and iterate through its records. It filters records by type (PIR and PTR) and extracts specific information like DUT count and continuity test results. ```rust use rust_stdf::{stdf_file::*, stdf_record_type::*, StdfRecord}; fn main() { let stdf_path = "demo_file.stdf"; // "demo_file.stdf.gz" "demo_file.stdf.bz2" let mut reader = match StdfReader::new(&stdf_path) { Ok(r) => r, Err(e) => { println!("{}", e); return; } }; // we will count total DUT# in the file // and put test result of PTR named // "continuity test" in a vector. let mut dut_count: u64 = 0; let mut continuity_rlt = vec![]; // use type filter to work on certain types, // use `|` to combine multiple typs let rec_types = REC_PIR | REC_PTR; // iterator starts from current file position, // if file hits EOF, it will NOT redirect to 0. for rec in reader .get_record_iter() .map(|x| x.unwrap()) .filter(|x| x.is_type(rec_types)) { match rec { StdfRecord::PIR(_) => {dut_count += 1;} StdfRecord::PTR(ref ptr_rec) => { if ptr_rec.test_txt == "continuity test" { continuity_rlt.push(ptr_rec.result); } } _ => {} } } println!("Total duts {} \n continuity result {:?}", dut_count, continuity_rlt); } ``` -------------------------------- ### Add rust-stdf Dependency to Cargo.toml Source: https://github.com/noonchen/rust-stdf/blob/main/README.md This snippet shows how to add the rust-stdf library as a dependency in your Cargo.toml file. It specifies the version and available features. ```toml # Cargo.toml [dependencies] rust-stdf = "0.3.1" ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.