bitsandbytes 0.3.2

An owned, bit-aware binary codec: fast bit/byte field types and the unified #[bin] macro.
Documentation
[package]
name = "bitsandbytes"
version = "0.3.2"
edition.workspace = true
license.workspace = true
repository.workspace = true
rust-version.workspace = true
description = "An owned, bit-aware binary codec: fast bit/byte field types and the unified #[bin] macro."
readme = "README.md"
keywords = ["bitfield", "codec", "binary", "no_std", "protocol"]
categories = ["encoding", "parsing", "no-std", "network-programming"]

# docs.rs builds with all features (so the `std` ladder and `bytes` adapters are
# documented) and `--cfg docsrs`, which lights up the per-item feature badges
# (`#![cfg_attr(docsrs, feature(doc_auto_cfg))]` in lib.rs).
[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[lib]
# Published as `bitsandbytes`, but the library is named `bnb` — so the crate's own
# tests/doctests/examples and downstream `bnb = { package = "bitsandbytes" }`
# consumers all import it as `bnb`.
name = "bnb"

[dependencies]
# The derive/attribute macros live in a sibling proc-macro crate (a proc-macro
# crate cannot also export runtime items). Re-exported below so users only
# depend on `bnb`.
bnb-macros = { workspace = true }
# Structured diagnostics: the `#[br(dbg)]` directive emits a `tracing` event (TRACE,
# target `bnb::dbg`). Optional, pulled in by the `std` feature — `tracing`'s default
# features link `std`, and the workspace dep can't be overridden here, so `#[br(dbg)]`
# is a `std`-only debugging aid (an embedded build uses its own logger).
tracing = { workspace = true, optional = true }
# Optional: zero-copy `Source`/`Sink` over the `bytes` crate (own a `Bytes` frame to
# decode, encode to a `Bytes` to send) — for async/tokio framing. Off by default so
# the core stays dependency-light; users off tokio never pull it in. The adapters are
# inherently a std/tokio concern, so the `bytes` feature also turns on `std`.
bytes = { workspace = true, optional = true }
# Optional: the `tokio_util::codec` adapter ([`BinCodec`]) for async framing. Off by
# default; pulled in only by the `tokio` feature.
tokio-util = { workspace = true, optional = true }

[features]
# `std` (default) enables the `std::io` ladder (`StreamBitReader`/`BufSource`/
# `SeekReader`, the `encode(writer)` convenience, `From<std::io::Error>`) and the
# `tracing`-backed `#[br(dbg)]` directive. Without it `bnb` is `no_std` — it always
# needs `alloc`: decode from `&[u8]`, encode to `Vec<u8>`.
default = ["std"]
std = ["dep:tracing"]
# `bytes`-crate adapters (`BytesReader`/`BytesWriter`); imply `std` (tokio framing).
bytes = ["dep:bytes", "std"]
# `BinCodec`: a `tokio_util::codec` Decoder/Encoder for any `#[bin]` message (async framing
# over `tokio`). Needs the `bytes` adapters' `BytesMut`, so it implies `bytes`.
tokio = ["dep:tokio-util", "bytes"]
# Ergonomic std socket helpers (`MessageStream` over a `Read + Write` stream, `MessageDatagram`
# over a `DatagramSocket`). Pure std — no extra deps.
net = ["std"]
# Test-only mock transport (`MockDatagramSocket`) for exercising `net` code without real sockets.
# Put it in your `[dev-dependencies]` features, not your release build.
mock = ["net"]

[dev-dependencies]
# Real logging in the examples (instead of `println!`). `tracing` is also an optional
# runtime dep (the `std` feature, for `#[br(dbg)]`); as a dev-dep it's always available
# to examples, and `tracing-subscriber` renders the events.
tracing.workspace = true
tracing-subscriber.workspace = true
# Compile-fail UI tests: assert that `#[bin]`/`#[bitfield]` misuse is rejected with
# a clear, well-spanned error. Regenerate snapshots with `TRYBUILD=overwrite`.
trybuild.workspace = true
# Property-based round-trip stress testing.
proptest.workspace = true
# `tests/serde_compat.rs`: pins the 1.0 scope line — user-side serde derives coexist with
# plain `#[bin]` types; serde-as-data-format is explicitly out of scope (see ROADMAP.md).
serde.workspace = true
serde_json.workspace = true
# Statistical benchmarking with HTML reports. The benches use `Criterion::default()`
# directly (no shared `testutil` harness) so `bnb` stays self-contained / publishable.
criterion = { workspace = true, features = ["html_reports"] }
# The crates `bnb` replaces — used *only* in benchmarks to substantiate the
# "as fast as a hand-written shift/mask" claim before any migration. They are
# dev-dependencies, so they never enter a real build.
bitbybit.workspace = true
arbitrary-int.workspace = true
modular-bitfield-msb.workspace = true
# The `tokio_framed` example drives `bnb::BinCodec` (the `tokio` feature) over a real async
# socket. The runtime + the `Stream`/`Sink` ext traits are dev-only; `tokio-util` comes from
# the `tokio` feature.
tokio.workspace = true
futures-util.workspace = true

# The `framed` example exercises the opt-in `bytes` adapters, so it only builds with
# `--features bytes` (default `cargo build`/`test` skip it; the others auto-discover).
[[example]]
name = "framed"
required-features = ["bytes"]

[[example]]
name = "bytes_frame"
required-features = ["bytes"]

# `tokio_framed` (TCP) and `tokio_udp` (UDP) drive `bnb::BinCodec`; gated on `tokio` so default
# builds skip them (and the heavy async deps).
[[example]]
name = "tokio_framed"
required-features = ["tokio"]

[[example]]
name = "tokio_udp"
required-features = ["tokio"]

# `sockets` and `unix_stream` show the `net` feature's helpers (`MessageStream`/`MessageDatagram`).
[[example]]
name = "sockets"
required-features = ["net"]

[[example]]
name = "unix_stream"
required-features = ["net"]

# `mock_datagram`/`mock_stream` show testing `net` code with the `mock` feature's in-memory transports.
[[example]]
name = "mock_datagram"
required-features = ["mock"]

[[example]]
name = "mock_stream"
required-features = ["mock"]

[[bench]]
name = "bitfield_bench"
harness = false

[[bench]]
name = "bitstream_bench"
harness = false

[[bench]]
name = "message_bench"
harness = false

[lints]
workspace = true