Skip to main content

http_streams_core/
envelope.rs

1//! Wrapping a streamed array in a surrounding JSON object.
2
3/// An object to wrap a streamed JSON array in.
4///
5/// The array is emitted as `array_field` of `object`, so
6/// `StreamFormatEnvelope { object: Meta { total: 3 }, array_field: "items" }` produces
7/// `{"total":3,"items":[…]}`.
8///
9/// Only one level of nesting is supported: the array is always a direct field of the envelope
10/// object. This is a consequence of how the framing works: the envelope is serialised once,
11/// its trailing `}` is stripped, and the array is appended. It is not something a deeper path
12/// could be threaded through.
13#[derive(Debug, Clone)]
14pub struct StreamFormatEnvelope<E> {
15    /// The object to wrap the array in.
16    pub object: E,
17    /// The field of `object` that the array is emitted as.
18    pub array_field: String,
19}