Skip to main content

Json

Struct Json 

Source
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: bool

Whether the next value needs a , in front of it. Reset on entering a container, set after every value.

Implementations§

Source§

impl Json

Source

pub fn new() -> Self

Source

pub fn into_string(self) -> String

Source

fn sep(&mut self)

Source

pub fn obj(&mut self, f: impl FnOnce(&mut Self))

Write a {...}. Inside f, call key then a value.

Source

pub fn arr(&mut self, f: impl FnOnce(&mut Self))

Write a [...].

Source

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.

Source

pub fn str(&mut self, s: &str)

Source

pub fn i64(&mut self, v: i64)

Source

pub fn u64(&mut self, v: u64)

Source

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.

Source

pub fn u64_str(&mut self, v: u64)

Source

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 -.

Source

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.

Source

pub fn bool(&mut self, v: bool)

Source

pub fn null(&mut self)

Source

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.

Source

pub fn hex(&mut self, bytes: &[u8])

Lowercase hex of bytes, as one string. Trace and span ids are FixedSizeBinary on disk and hex everywhere a human or a W3C header sees them.

Trait Implementations§

Source§

impl Default for Json

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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
where T: RefUnwindSafe + Send + Sync,

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> IntoRequest<T> for T

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more