pub struct Json {
buf: String,
comma: bool,
}Expand description
Incrementally built JSON. key before a value inside obj, bare values
inside arr.
Fields§
§buf: String§comma: boolWhether the next value needs a , in front of it. Reset on entering a
container, set after every value.
Implementations§
Source§impl Json
impl Json
pub fn new() -> Self
pub fn into_string(self) -> String
fn sep(&mut self)
Sourcepub fn obj(&mut self, f: impl FnOnce(&mut Self))
pub fn obj(&mut self, f: impl FnOnce(&mut Self))
Write a {...}. Inside f, call key then a value.
Sourcepub fn key(&mut self, k: &str)
pub fn key(&mut self, k: &str)
A member name. The value that follows attaches to it, so comma stays
as it was rather than being armed here.
pub fn str(&mut self, s: &str)
pub fn i64(&mut self, v: i64)
pub fn u64(&mut self, v: u64)
Sourcepub fn i64_str(&mut self, v: i64)
pub fn i64_str(&mut self, v: i64)
A 64-bit integer as a JSON string, which is what OTLP/JSON says a 64-bit integer is.
Principle 3 decides this: where OTLP specifies an encoding, OTLP wins.
The spec makes int64, sfixed64 and uint64 strings on the wire, the
ingest decoder already reads them that way (section 0), and a response Mira
cannot feed back to itself as a request body is not a round trip. The
mechanical reason is the same in both directions: a JSON number is an
IEEE754 double to a browser and to most parsers, time_unix_nano is
~1.7e18, and 2^53 is where a double stops counting. Bare-number output
does not fail there, it silently rounds.
Only the 64-bit columns go through this. A severity_number, a
status_code or a dropped_* is 32 bits or smaller, arithmetic on it
is what a reader wants, and no double loses it.
pub fn u64_str(&mut self, v: u64)
Sourcefn quoted_digits(&mut self, digits: &str)
fn quoted_digits(&mut self, digits: &str)
Quote without escaping: the input is to_string of an integer, so it is
ASCII digits and at most a leading -.
Sourcepub fn f64(&mut self, v: f64)
pub fn f64(&mut self, v: f64)
Non-finite becomes null. JSON has no NaN or Infinity, and both turn up
in real metrics — a histogram sum over no observations, a gauge from a
division by zero. Emitting the bare token would produce a document that
every strict parser, including the browser’s, rejects outright, taking
the whole response down with it rather than the one field.
pub fn bool(&mut self, v: bool)
pub fn null(&mut self)
Sourcepub fn raw(&mut self, fragment: &str)
pub fn raw(&mut self, fragment: &str)
Splice in a fragment this writer produced earlier — a rendered value, or
a run of "k":v,"k":v members inside an object.
The escape hatch for the one thing the closure API cannot express: caching. A metric’s descriptor and its resource attributes are identical across every point of a series, and re-rendering them per point is the difference between a chart query that costs one pass and one that costs two. Empty is a no-op so a cached fragment that turned out to be empty cannot emit a stray comma.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Json
impl RefUnwindSafe for Json
impl Send for Json
impl Sync for Json
impl Unpin for Json
impl UnsafeUnpin for Json
impl UnwindSafe for Json
Blanket Implementations§
impl<T> Allocation for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].