5 unstable releases

Uses new Rust 2024

new 0.3.1 Mar 6, 2026
0.3.0 Mar 18, 2025
0.2.1 Aug 26, 2024
0.2.0 Oct 10, 2022
0.1.0 Sep 30, 2021

#13 in #btree-map

30 downloads per month
Used in 13 crates (8 directly)

MIT/Apache

19KB
373 lines

data-stream is a binary serialization library focused on simplicity.

It provides two core traits:

  • ToStream
  • FromStream

Implement these traits for your types to write to impl Write and read from impl Read.

Why?

This crate is built for straightforward binary I/O without a large abstraction layer.

Many existing solutions are built around broader data models and generic serialization frameworks. That can be useful, but it can also add complexity when you only want explicit binary read/write behavior.

With data-stream, manual implementations are simple: you write or read fields in the order you define.

Because everything is stream-based, integration with files, sockets, and in-memory buffers is direct.

Features

Implemented:

  • Booleans (bool)
  • Numbers (u8 to u128, i8 to i128, f32, f64, usize)
  • Fixed-size arrays ([T; N])
  • Text types (char, String, str for writing)
  • Wrapper types (Box, Option, Result)
  • Collections (Vec, VecDeque, LinkedList, HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap)
  • Derive macros (data-stream-derive)

Settings:

  • Endianness via EndianSettings
  • Collection/string size encoding via SizeSettings
  • Ready-to-use defaults:
    • default_settings::NativeSettings
    • default_settings::PortableSettings

Notes

  • PortableSettings is recommended for stable cross-platform binary formats.
  • NativeSettings is useful for local/native performance-oriented formats.
  • str supports writing (ToStream), while owned text reading is done via String (FromStream).

Dependencies

~76KB