body 0.1.0

Policy-managed body lifecycle primitives for Rust systems.
Documentation
  • Coverage
  • 100%
    60 out of 60 items documented0 out of 27 items with examples
  • Size
  • Source code size: 15.47 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 788.51 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 4s Average build duration of successful builds.
  • all releases: 4s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • iadev09/body
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • iadev09

body

Policy-managed body lifecycle primitives for Rust systems.

body is about the lifecycle of payloads: limits, draining, replay, shutdown, failure semantics, observability, and ownership boundaries.

It does not replace http-body, http-body-util, hyper, tower, or bytes. Those crates provide excellent protocol-level and utility-level building blocks. body aims to provide a higher-level policy layer around them.

Status

body is an early foundation release.

The initial API is intentionally small: it establishes the vocabulary, policy types, and lifecycle model that later protocol integrations will build on. Support for http-body, hyper, tower, and async runtimes is planned as the semantics settle.

Why

Bodies are not just bytes.

A request, response, message, stream, or payload body has operational consequences:

  • it may be streamed, buffered, rejected, drained, replayed, or aborted
  • it may exceed limits
  • it may begin as a future body that is not a stream yet
  • it may outlive the request or message head
  • it may affect connection reuse
  • it may interact with graceful shutdown
  • it may need observability and accounting
  • it may need different behavior under upstream failure

body exists to make those semantics explicit.

Protocol Independence

body is protocol-independent.

It treats a body as a payload lifecycle boundary, not as an HTTP-only type. HTTP request and response bodies are important use cases, but the same policy questions appear in TCP, Unix sockets, UDP, QUIC, WebTransport, WebSocket, RPC, uploads, downloads, and other streamed payload systems.

Protocol integrations will come later as optional crates or features.

Non-goals

  • This crate does not replace http-body.
  • This crate does not compete with http-body-util.
  • This crate does not hide protocol crates behind a large framework.
  • This crate does not force a single async runtime.
  • This crate does not promise every protocol integration in 0.1.

Initial API

The first public API focuses on policy and lifecycle vocabulary:

  • BodyPolicy
  • BodyState
  • BodyGuard
  • BodyDecision
  • OverflowPolicy
  • DropPolicy
  • DrainPolicy
  • ReplayPolicy
  • ShutdownPolicy

Example

use body::{BodyDecision, BodyGuard, OverflowPolicy};

let mut body = BodyGuard::new(())
    .max_bytes(1024)
    .overflow(OverflowPolicy::DrainThenReject);

assert_eq!(body.observe_bytes(512), BodyDecision::Continue);
assert_eq!(body.observe_bytes(600), BodyDecision::DrainThenReject);

Planned timeline

0.1

Foundation release.

  • core policy types
  • lifecycle state model
  • minimal BodyGuard<B>
  • protocol-independent byte accounting decisions
  • documentation of semantics and non-goals

0.2

HTTP body integration.

  • http-body compatibility
  • byte counting
  • limit enforcement
  • error classification

0.3

Operational semantics.

  • drain helpers
  • timeout hooks
  • shutdown behavior
  • observability hooks

0.4

Integration layer.

  • optional hyper support
  • optional tower support
  • test bodies for slow, endless, partial, and failing streams

Philosophy

The head declares intent.

The body carries consequence.