Expand description
§xportrs
Pure Rust SAS XPORT (XPT) reader and writer for CDISC clinical trial data submissions.
xportrs provides a safe, DataFrame-agnostic implementation of XPT v5 I/O
with built-in regulatory compliance validation for FDA, PMDA, and NMPA submissions.
§Quick Start
§Reading an XPT file
use xportrs::Xpt;
// Read the first dataset from a file
let dataset = Xpt::read("ae.xpt")?;
println!("Domain: {}", dataset.domain_code());
println!("Rows: {}", dataset.nrows());
// Read a specific member from a multi-dataset file
let dm = Xpt::reader("study.xpt")?.read_member("DM")?;§Writing an XPT file
use xportrs::{Xpt, Agency, Dataset, Column, ColumnData};
let dataset = Dataset::new(
"AE", // Domain code (accepts &str, String, or DomainCode)
vec![
Column::new("USUBJID", ColumnData::String(vec![
Some("01-001".into()),
Some("01-002".into()),
])),
Column::new("AESEQ", ColumnData::I64(vec![Some(1), Some(1)])),
],
)?;
// Write with structural validation only
Xpt::writer(dataset.clone()).finalize()?.write_path("ae.xpt")?;
// Write with FDA agency compliance validation
let mut builder = Xpt::writer(dataset);
builder.agency(Agency::FDA);
builder.finalize()?.write_path("ae_fda.xpt")?;§Entry Points
The Xpt struct provides all main functionality:
Xpt::read- Read a file in one lineXpt::reader- Read with options (member selection, etc.)Xpt::writer- Build a validated write planXpt::inspect- Examine file metadata without loading data
§Data Types
Dataset- Tabular data container with domain code and columnsColumn- Single variable with name and dataColumnData- Type-safe column values (numeric, character, date/time)DomainCode- Type-safe domain identifier (e.g., “AE”, “DM”, “LB”)Label- Type-safe label string for datasets and variables
§Validation & Compliance
Agency- Regulatory agencies (Agency::FDA,Agency::PMDA,Agency::NMPA)Issue- Validation problems with severity and contextSeverity-Severity::Error(blocking) orSeverity::Warning(informational)
When an agency is specified, the following rules are enforced:
- ASCII-only names, labels, and character values
- Dataset names: max 8 bytes, uppercase alphanumeric
- Variable names: max 8 bytes, uppercase alphanumeric with underscores
- Labels: max 40 bytes
- Character values: max 200 bytes
- Automatic file splitting for files exceeding 5GB
§Feature Flags
| Feature | Description |
|---|---|
serde | Serialization/deserialization support |
tracing | Structured logging with the tracing crate |
polars | Polars DataFrame integration |
full | All optional features |
§CDISC Terminology
This crate uses CDISC SDTM vocabulary:
- Domain dataset: A table identified by a
DomainCode(e.g., “AE”, “DM”, “LB”) - Observation: One row/record in the
Dataset - Variable: One
Column; may have aVariableRole
Re-exports§
pub use agency::Agency;pub use config::TextMode;pub use config::Verbosity;pub use dataset::Column;pub use dataset::ColumnData;pub use dataset::ColumnNames;pub use dataset::Dataset;pub use dataset::DomainCode;pub use dataset::Format;pub use dataset::FormatParseError;pub use dataset::IntoIter;pub use dataset::Iter;pub use dataset::IterMut;pub use dataset::Justification;pub use dataset::Label;pub use dataset::VariableName;pub use dataset::VariableRole;pub use metadata::XptVarType;pub use validate::Issue;pub use validate::Severity;pub use xpt::XptVersion;
Modules§
- agency
- Regulatory agency definitions for compliance validation.
- config
- Configuration types for xportrs.
- dataset
- Dataset types for xportrs.
- metadata
- Metadata types for xportrs.
- temporal
- Temporal conversion utilities.
- validate
- Validation for xportrs.
- xpt
- XPT format implementation.
Structs§
- Validated
Write - An immutable, validated write plan ready for execution.
- Xpt
- Unified entry point for XPT file operations.
- XptInfo
- Information about an XPT file.
- XptReader
Builder - Builder for reading XPT files with custom options.
- XptWriter
Builder - A mutable builder for XPT write operations.
Enums§
- Error
- The main error type for xportrs operations.