dcm4rs
A foundational DICOM library for Rust. Phase one is complete: data model + data dictionary.
Layout
Cargo.toml virtual workspace
dcm4rs/ library: data model (Tag / Vr / Value / Element / DataSet) + data dictionary
cli/ command-line package: depends on dcm4rs only, not part of the library's public API
data/ PS3.6 DocBook source (not committed)
With just two packages there is no crates/ layer: uv, ruff and rust-analyzer use crates/
because they have dozens of members; two packages read more directly in the flat layout used by
clap / tokio / serde, and cargo run -p cli is just as short.
Dependencies flow one way: cli ──▶ dcm4rs; the library never depends on the command-line tool.
Third parties depend only on the dcm4rs library, not on cli. New commands (validate, dump,
transcode, ...) go into cli/src/bin/; the library itself ships no binary.
The naming follows the shape of pydicom / fo-dicom: one library package, with the dictionary as
a module inside it (dcm4rs::dictionary), rather than splitting it into core / dict packages
the way dcm4che does — Java can call a package dcm4che-core, but in Rust the name core clashes
with the sysroot crate, so copying that split would only bring trouble. If the dictionary ever
needs to be compiled separately, dcm4rs-dictionary can be split out then.
Design decisions
- Values are stored as raw bytes.
Value::Byteskeeps the bytes that appear in the standard; interpreting numbers and text happens at read time. Data under any transfer syntax (explicit or implicit VR, big endian) can be written back byte for byte, and the parser never has to guess. - Explicit endianness. Decoders such as
Element::u16s(endian)require anEndian, andDataSetcarries one set from the transfer syntax for convenience accessors such asds.u16(tag). There is no hidden global state. - Strict rather than lenient. A VR that does not match the decoding, a length that is not a
multiple of the unit, or text that is not valid UTF-8 all produce explicit errors
(
Error::WrongVr/WrongLength/InvalidUtf8) instead of silently yielding garbage. - Tag order is standard order.
DataSetstores elements in aBTreeMap, so iteration is naturally ascending by (group, element), matching the order required for writing. - Zero dependencies. Easy to embed in long-lived products such as a PACS, and avoids supply chain risk.
Usage
use tags;
use ;
let mut ds = new;
ds.set_string;
ds.set_u16;
ds.set;
assert_eq!;
assert_eq!;
assert_eq!;
// Big-endian transfer syntax: bytes are stored big endian and declared when decoding
let mut big = with_endian;
big.set;
assert_eq!;
// Dictionary lookup
let entry = lookup.unwrap;
assert!; // OB or OW, decided by context
Tests and checks
Data dictionary
Generated from the official PS3.6 (currently 2026d): 5212 standard elements (retired ones
included), 88 repeating groups, 5212 tag constants. The generator lives in
cli/src/bin/dictgen.rs; it depends on dcm4rs to validate VRs and keeps no second VR list. The
generated file is committed, so building needs no network access; see
data/README.md to regenerate:
Not implemented yet (next phase)
- Charset decoding:
SpecificCharacterSet→encoding_rsencodings (including ISO 2022 escape sequences). Todaystring()only decodes UTF-8, so data in non-UTF-8 charsets returnsInvalidUtf8. That step brings inencoding_rs(unless we maintain our own tables), turning "zero dependencies" into "only encoding_rs". - File and stream parsing/writing (
encode): explicit/implicit VR, deflate, undefined lengths, encapsulated pixel data. - Transfer syntax registry and compression/decompression.
- Pixel data decoding (RLE, the JPEG family).
- UL/DIMSE network layer: a separate package
dcm4rs-net(following pynetdicom and dcm4che-net) that depends ondcm4rs. Networking needs an async/thread runtime, so it stays out of the core library;dcm4rsremains lean (association, C-FIND/C-MOVE/C-GET, ...).
Reference implementations
Semantics follow pydicom / pynetdicom, conformance and edge-case encoding are checked against DCMTK, the async network API shape follows fo-dicom, and the enterprise feature list follows dcm4che.
License
MIT OR Apache-2.0.