tdms-rs
A pure Rust library for reading and writing National Instruments TDMS (Technical Data Management Streaming) files with full format support and excellent performance.
Getting Started
Installation
Add tdms-rs to your Cargo.toml:
[]
= "1.0"
Quick Start - Reading TDMS Files
use TdmsFile;
use Path;
Quick Start - Writing TDMS Files
use ;
Features
- Complete TDMS Support: Read and write all TDMS data types and structures
- High Performance: Zero-copy parsing and efficient memory usage
- Type Safety: Rust's type system prevents common data handling errors
- Production Ready: Comprehensive test coverage with 24+ test scenarios
- Binary Compatibility: Output files work with National Instruments software
- Pure Rust: Minimal external dependencies
New in v1.0.0 - Ergonomic Improvements
- 🎯 From Property Conversions:
writer.add_property("key", "value")instead of verbosePropertyValue::String() - 🔧 Complete Helper Methods: Type-safe accessors for all data types (
as_i8(),as_u8(),as_bool(), etc.) - 🚀 Ergonomic Channel Lookup:
file.get_channel("group", "channel")for direct access - 📋 Property Constants: Well-known TDMS property names (
properties::UNIT_STRING, etc.) - ⏰ Timestamp Conversion: Easy conversion helpers (
timestamps_to_unix(),as_timestamps_f64()) - 📖 Enhanced Documentation: Comprehensive examples and API documentation
Getting Started
Add to your Cargo.toml:
[]
= "1.0"
Reading TDMS Files
use TdmsFile;
use Path;
// Load a TDMS file
let file = load?;
// Ergonomic channel access (v1.0.0)
if let Some = file.get_channel
// Error handling with descriptive messages
match file.try_get_channel
// Traditional iteration still available
for in &file.groups
Writing TDMS Files
use ;
// Create a new TDMS file
let mut writer = new;
// Add file-level properties (v1.0.0 ergonomic syntax)
writer.add_property?;
writer.add_property?;
writer.add_property?;
// Create a group with channels
let group = writer.add_group?;
group.add_property?;
// Add channels with different data types
group.add_channel?;
group.add_channel?;
group.add_channel?;
// Add channel properties with ergonomic syntax
let voltage_channel = group.add_channel?;
voltage_channel.add_property?;
voltage_channel.add_property?;
// Write the file
writer.write?;
API Overview
Core Types
TdmsFile: Root container with groups and file-level propertiesTdmsGroup: Container for related channels with group-level propertiesTdmsChannel: Individual data stream with properties and typed dataTdmsData: Enum containing all supported TDMS data typesPropertyValue: Enum for metadata values (strings, numbers, timestamps, etc.)
Reading API
use ;
use Path;
let file = load?;
// Ergonomic channel access
let channel = file.get_channel?;
// Complete family of type-safe data accessors
match channel.data_type_name
// Property access with constants and helpers
if let Some = channel.unit
if let Some = channel.description
// Using property constants to avoid magic strings
if let Some = channel.get_double_property
Writing API
use ;
let mut writer = new;
// File properties with ergonomic From<T> conversions
writer.add_property?;
writer.add_property?;
writer.add_property?;
writer.add_property?;
// Create groups and channels
let group = writer.add_group?;
group.add_property?;
// Add channels with data
group.add_channel?;
group.add_channel?;
// Add channel properties
let channel = group.add_channel?;
channel.add_property?;
channel.add_property?;
writer.write?;
Supported Data Types
| TDMS Type | Rust Type | Description |
|---|---|---|
| I8 | i8 |
8-bit signed integer |
| I16 | i16 |
16-bit signed integer |
| I32 | i32 |
32-bit signed integer |
| I64 | i64 |
64-bit signed integer |
| U8 | u8 |
8-bit unsigned integer |
| U16 | u16 |
16-bit unsigned integer |
| U32 | u32 |
32-bit unsigned integer |
| U64 | u64 |
64-bit unsigned integer |
| Float | f32 |
32-bit floating point |
| Double | f64 |
64-bit floating point |
| String | String |
UTF-8 encoded text |
| Boolean | bool |
True/false values |
| TimeStamp | (i64, u64) |
TDMS timestamp (seconds since 1904, fraction) |
All data types support special values (NaN, Infinity) and edge cases.
Examples
The repository includes comprehensive examples:
Reading Examples
Writing Examples
Timestamp Examples
Performance & Guarantees
Memory Efficiency
- Zero-copy parsing where possible
- Streaming reads for large files
- Minimal allocations during parsing
- Owned data for safe multi-threading
Binary Compatibility
- Corpus verified: Output matches National Instruments reference files
- Round-trip tested: Write → read cycles preserve all data
- Deterministic output: Consistent file generation
Format Guarantees
- Data Integrity: All TDMS data types supported with full precision
- Property Preservation: File, group, and channel metadata maintained
- Deterministic Output: Groups and channels written in alphabetical order
- Binary Compatibility: Files work with National Instruments software
Command Line Tool
Install the binary tool:
Validate and inspect TDMS files:
The tool displays file structure, validates format, and shows property summaries.
Error Handling
The library uses Rust's Result type for comprehensive error handling:
use TdmsFile;
use Path;
match load
Common error scenarios:
- File not found or permission denied
- Invalid TDMS file format
- Corrupted or truncated files
- Unsupported TDMS features
Testing
The library includes comprehensive test coverage:
Test corpus includes 24+ TDMS files covering:
- Basic file structures
- All data types and edge cases
- Unicode support
- Large and sparse data
- Multi-segment files
- Property metadata
Version 1.0.0 Release
This is the first stable release of tdms-rs, providing:
- Production Ready: Complete TDMS read/write support with comprehensive testing
- All Data Types: Full support for TDMS data types and properties
- Writer API: Create TDMS files from Rust data structures
- Binary Compatibility: Output verified against National Instruments corpus
- Comprehensive Testing: 24+ test scenarios covering edge cases and data types
- Semantic Versioning Promise: Breaking changes only in major versions
See CHANGELOG.md for detailed release notes.
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass with
cargo test - Follow Rust formatting with
cargo fmt - Submit a pull request
Development Setup
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE)
- MIT License (LICENSE-MIT)
at your option.
Acknowledgments
- National Instruments for the TDMS format specification
- The Rust community for excellent tooling and libraries
- Contributors who helped improve the library