tracing-serde-0.1.3/.cargo_vcs_info.json0000644000000001530000000000100135630ustar { "git": { "sha1": "c661c23089a6ba123b4cef830023903515905370" }, "path_in_vcs": "tracing-serde" }tracing-serde-0.1.3/CHANGELOG.md000064400000000000000000000025440072674642500142220ustar 00000000000000# 0.1.3 (February 4, 2022) This release adds *experimental* support for recording structured field values using the [`valuable`] crate. See [this blog post][post] for details on `valuable`. Note that `valuable` support currently requires `--cfg tracing_unstable`. See the documentation for details. ### Added - **valuable**: Experimental support for serializing user-defined types using [`valuable`] and [`valuable-serde`] ([#1862]) - Support for serializing `f64` values ([#1507]) ### Fixed - Fixed incorrect size hint in `SerializeFieldSet` ([#1333]) - A number of documentation fixes Thanks to @akinnane and @maxburke for contributing to this release! [`valuable`]: https://crates.io/crates/valuable [`valuable-serde`]: https://crates.io/crates/valuable-serde [post]: https://tokio.rs/blog/2021-05-valuable [#1862]: https://github.com/tokio-rs/tracing/pull/1862 [#1507]: https://github.com/tokio-rs/tracing/pull/1507 [#1333]: https://github.com/tokio-rs/tracing/pull/1333 # 0.1.2 (September 11, 2020) ### Added - `SerdeMapVisitor::finish` to complete serializing the visited objects (#892) - `SerdeMapVisitor::take_serializer` to return the serializer wrapped by a `SerdeMapVisitor` (#892) # 0.1.1 (February 27, 2020) ### Added - Made `SerdeMapVisitor` public (#599) - Made `SerdeStructVisitor` public (#599) # 0.1.0 (November 18, 2019) - Initial release tracing-serde-0.1.3/Cargo.toml0000644000000026650000000000100115730ustar # THIS FILE IS AUTOMATICALLY GENERATED BY CARGO # # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies # to registry (e.g., crates.io) dependencies. # # If you are reading this file be aware that the original Cargo.toml # will likely look very different (and much more reasonable). # See Cargo.toml.orig for the original contents. [package] edition = "2018" rust-version = "1.42.0" name = "tracing-serde" version = "0.1.3" authors = ["Tokio Contributors "] description = "A compatibility layer for serializing trace data with `serde`\n" homepage = "https://tokio.rs" keywords = ["logging", "tracing", "serialization"] categories = ["development-tools::debugging", "development-tools::profiling", "asynchronous", "encoding"] license = "MIT" repository = "https://github.com/tokio-rs/tracing" [dependencies.serde] version = "1" [dependencies.tracing-core] version = "0.1.22" [dev-dependencies.serde_json] version = "1" [features] valuable = ["valuable_crate", "valuable-serde", "tracing-core/valuable"] [target."cfg(tracing_unstable)".dependencies.valuable-serde] version = "0.1.0" optional = true default_features = false [target."cfg(tracing_unstable)".dependencies.valuable_crate] version = "0.1.0" optional = true default_features = false package = "valuable" [badges.maintenance] status = "experimental" tracing-serde-0.1.3/Cargo.toml.orig000064400000000000000000000017440072674642500153010ustar 00000000000000[package] name = "tracing-serde" version = "0.1.3" authors = ["Tokio Contributors "] license = "MIT" edition = "2018" repository = "https://github.com/tokio-rs/tracing" homepage = "https://tokio.rs" description = """ A compatibility layer for serializing trace data with `serde` """ categories = [ "development-tools::debugging", "development-tools::profiling", "asynchronous", "encoding", ] keywords = ["logging", "tracing", "serialization"] rust-version = "1.42.0" [features] valuable = ["valuable_crate", "valuable-serde", "tracing-core/valuable"] [dependencies] serde = "1" tracing-core = { path = "../tracing-core", version = "0.1.22"} [dev-dependencies] serde_json = "1" [target.'cfg(tracing_unstable)'.dependencies] valuable_crate = { package = "valuable", version = "0.1.0", optional = true, default_features = false } valuable-serde = { version = "0.1.0", optional = true, default_features = false } [badges] maintenance = { status = "experimental" } tracing-serde-0.1.3/LICENSE000064400000000000000000000020460072674642500134130ustar 00000000000000Copyright (c) 2019 Tokio Contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tracing-serde-0.1.3/README.md000064400000000000000000000077110072674642500136710ustar 00000000000000![Tracing — Structured, application-level diagnostics][splash] [splash]: https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/splash.svg # tracing-serde An adapter for serializing [`tracing`] types using [`serde`]. [![Documentation][docs-badge]][docs-url] [![Documentation (master)][docs-master-badge]][docs-master-url] [docs-badge]: https://docs.rs/tracing-serde/badge.svg [docs-url]: https://docs.rs/tracing-serde [docs-master-badge]: https://img.shields.io/badge/docs-master-blue [docs-master-url]: https://tracing-rs.netlify.com/tracing_serde ## Overview [`tracing`] is a framework for instrumenting Rust programs to collect scoped, structured, and async-aware diagnostics.`tracing-serde` enables serializing `tracing` types using [`serde`]. Traditional logging is based on human-readable text messages. `tracing` gives us machine-readable structured diagnostic information. This lets us interact with diagnostic data programmatically. With `tracing-serde`, you can implement a `Subscriber` to serialize your `tracing` types and make use of the existing ecosystem of `serde` serializers to talk with distributed tracing systems. Serializing diagnostic information allows us to do more with our logged values. For instance, when working with logging data in JSON gives us pretty-print when we're debugging in development and you can emit JSON and tracing data to monitor your services in production. The `tracing` crate provides the APIs necessary for instrumenting libraries and applications to emit trace data. *Compiler support: [requires `rustc` 1.42+][msrv]* [msrv]: #supported-rust-versions ## Usage First, add this to your `Cargo.toml`: ```toml [dependencies] tracing = "0.1" tracing-serde = "0.1" ``` Next, add this to your crate: ```rust use tracing_serde::AsSerde; ``` Please read the [`tracing` documentation](https://docs.rs/tracing/latest/tracing/index.html) for more information on how to create trace data. This crate provides the `as_serde` function, via the `AsSerde` trait, which enables serializing the `Attributes`, `Event`, `Id`, `Metadata`, and `Record` `tracing` values. For the full example, please see the [examples](../examples) folder. Implement a `Subscriber` to format the serialization of `tracing` types how you'd like. ```rust pub struct JsonSubscriber { next_id: AtomicUsize, // you need to assign span IDs, so you need a counter } impl Subscriber for JsonSubscriber { fn new_span(&self, attrs: &Attributes) -> Id { let id = self.next_id.fetch_add(1, Ordering::Relaxed); let id = Id::from_u64(id as u64); let json = json!({ "new_span": { "attributes": attrs.as_serde(), "id": id.as_serde(), }}); println!("{}", json); id } // ... } ``` After you implement your `Subscriber`, you can use your `tracing` subscriber (`JsonSubscriber` in the above example) to record serialized trace data. ## Supported Rust Versions Tracing is built against the latest stable release. The minimum supported version is 1.42. The current Tracing version is not guaranteed to build on Rust versions earlier than the minimum supported version. Tracing follows the same compiler support policies as the rest of the Tokio project. The current stable Rust compiler and the three most recent minor versions before it will always be supported. For example, if the current stable compiler version is 1.45, the minimum supported version will not be increased past 1.42, three minor versions prior. Increasing the minimum supported compiler version is not considered a semver breaking change as long as doing so complies with this policy. ## License This project is licensed under the [MIT license](LICENSE). ### Contribution Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Tokio by you, shall be licensed as MIT, without any additional terms or conditions. [`tracing`]: https://crates.io/crates/tracing [`serde`]: https://crates.io/crates/serdetracing-serde-0.1.3/src/fields.rs000064400000000000000000000030710072674642500150100ustar 00000000000000//! Support for serializing fields as `serde` structs or maps. use super::*; #[derive(Debug)] pub struct SerializeFieldMap<'a, T>(&'a T); pub trait AsMap: Sized + sealed::Sealed { fn field_map(&self) -> SerializeFieldMap<'_, Self> { SerializeFieldMap(self) } } impl<'a> AsMap for Event<'a> {} impl<'a> AsMap for Attributes<'a> {} impl<'a> AsMap for Record<'a> {} // === impl SerializeFieldMap === impl<'a> Serialize for SerializeFieldMap<'a, Event<'_>> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let len = self.0.fields().count(); let serializer = serializer.serialize_map(Some(len))?; let mut visitor = SerdeMapVisitor::new(serializer); self.0.record(&mut visitor); visitor.finish() } } impl<'a> Serialize for SerializeFieldMap<'a, Attributes<'_>> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let len = self.0.metadata().fields().len(); let serializer = serializer.serialize_map(Some(len))?; let mut visitor = SerdeMapVisitor::new(serializer); self.0.record(&mut visitor); visitor.finish() } } impl<'a> Serialize for SerializeFieldMap<'a, Record<'_>> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let serializer = serializer.serialize_map(None)?; let mut visitor = SerdeMapVisitor::new(serializer); self.0.record(&mut visitor); visitor.finish() } } tracing-serde-0.1.3/src/lib.rs000064400000000000000000000436010072674642500143130ustar 00000000000000//! # tracing-serde //! //! An adapter for serializing [`tracing`] types using [`serde`]. //! //! [![Documentation][docs-badge]][docs-url] //! [![Documentation (master)][docs-master-badge]][docs-master-url] //! //! [docs-badge]: https://docs.rs/tracing-serde/badge.svg //! [docs-url]: https://docs.rs/tracing-serde //! [docs-master-badge]: https://img.shields.io/badge/docs-master-blue //! [docs-master-url]: https://tracing-rs.netlify.com/tracing_serde //! //! ## Overview //! //! [`tracing`] is a framework for instrumenting Rust programs to collect //! scoped, structured, and async-aware diagnostics.`tracing-serde` enables //! serializing `tracing` types using [`serde`]. //! //! Traditional logging is based on human-readable text messages. //! `tracing` gives us machine-readable structured diagnostic //! information. This lets us interact with diagnostic data //! programmatically. With `tracing-serde`, you can implement a //! `Subscriber` to serialize your `tracing` types and make use of the //! existing ecosystem of `serde` serializers to talk with distributed //! tracing systems. //! //! Serializing diagnostic information allows us to do more with our logged //! values. For instance, when working with logging data in JSON gives us //! pretty-print when we're debugging in development and you can emit JSON //! and tracing data to monitor your services in production. //! //! The `tracing` crate provides the APIs necessary for instrumenting //! libraries and applications to emit trace data. //! //! *Compiler support: [requires `rustc` 1.42+][msrv]* //! //! [msrv]: #supported-rust-versions //! //! ## Usage //! //! First, add this to your `Cargo.toml`: //! //! ```toml //! [dependencies] //! tracing = "0.1" //! tracing-serde = "0.1" //! ``` //! //! Next, add this to your crate: //! //! ```rust //! use tracing_serde::AsSerde; //! ``` //! //! Please read the [`tracing` documentation](https://docs.rs/tracing/latest/tracing/index.html) //! for more information on how to create trace data. //! //! This crate provides the `as_serde` function, via the `AsSerde` trait, //! which enables serializing the `Attributes`, `Event`, `Id`, `Metadata`, //! and `Record` `tracing` values. //! //! For the full example, please see the [examples](../examples) folder. //! //! Implement a `Subscriber` to format the serialization of `tracing` //! types how you'd like. //! //! ```rust //! # use tracing_core::{Subscriber, Metadata, Event}; //! # use tracing_core::span::{Attributes, Id, Record}; //! # use std::sync::atomic::{AtomicUsize, Ordering}; //! use tracing_serde::AsSerde; //! use serde_json::json; //! //! pub struct JsonSubscriber { //! next_id: AtomicUsize, // you need to assign span IDs, so you need a counter //! } //! //! impl Subscriber for JsonSubscriber { //! //! fn new_span(&self, attrs: &Attributes<'_>) -> Id { //! let id = self.next_id.fetch_add(1, Ordering::Relaxed); //! let id = Id::from_u64(id as u64); //! let json = json!({ //! "new_span": { //! "attributes": attrs.as_serde(), //! "id": id.as_serde(), //! }}); //! println!("{}", json); //! id //! } //! //! fn event(&self, event: &Event<'_>) { //! let json = json!({ //! "event": event.as_serde(), //! }); //! println!("{}", json); //! } //! //! // ... //! # fn enabled(&self, _: &Metadata<'_>) -> bool { false } //! # fn enter(&self, _: &Id) {} //! # fn exit(&self, _: &Id) {} //! # fn record(&self, _: &Id, _: &Record<'_>) {} //! # fn record_follows_from(&self, _: &Id, _: &Id) {} //! } //! ``` //! //! After you implement your `Subscriber`, you can use your `tracing` //! subscriber (`JsonSubscriber` in the above example) to record serialized //! trace data. //! //! ### Unstable Features //! //! These feature flags enable **unstable** features. The public API may break in 0.1.x //! releases. To enable these features, the `--cfg tracing_unstable` must be passed to //! `rustc` when compiling. //! //! The following unstable feature flags are currently available: //! //! * `valuable`: Enables [`Visit::record_value`] implementations, for //! serializing values recorded using the [`valuable`] crate. //! //! #### Enabling Unstable Features //! //! The easiest way to set the `tracing_unstable` cfg is to use the `RUSTFLAGS` //! env variable when running `cargo` commands: //! //! ```shell //! RUSTFLAGS="--cfg tracing_unstable" cargo build //! ``` //! Alternatively, the following can be added to the `.cargo/config` file in a //! project to automatically enable the cfg flag for that project: //! //! ```toml //! [build] //! rustflags = ["--cfg", "tracing_unstable"] //! ``` //! //! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section //! [`valuable`]: https://crates.io/crates/valuable //! //! ## Supported Rust Versions //! //! Tracing is built against the latest stable release. The minimum supported //! version is 1.42. The current Tracing version is not guaranteed to build on //! Rust versions earlier than the minimum supported version. //! //! Tracing follows the same compiler support policies as the rest of the Tokio //! project. The current stable Rust compiler and the three most recent minor //! versions before it will always be supported. For example, if the current //! stable compiler version is 1.45, the minimum supported version will not be //! increased past 1.42, three minor versions prior. Increasing the minimum //! supported compiler version is not considered a semver breaking change as //! long as doing so complies with this policy. //! //! [`tracing`]: https://crates.io/crates/tracing //! [`serde`]: https://crates.io/crates/serde #![doc(html_root_url = "https://docs.rs/tracing-serde/0.1.3")] #![doc( html_logo_url = "https://raw.githubusercontent.com/tokio-rs/tracing/master/assets/logo-type.png", issue_tracker_base_url = "https://github.com/tokio-rs/tracing/issues/" )] #![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, deny(rustdoc::broken_intra_doc_links))] #![warn( missing_debug_implementations, // missing_docs, // TODO: add documentation rust_2018_idioms, unreachable_pub, bad_style, const_err, dead_code, improper_ctypes, non_shorthand_field_patterns, no_mangle_generic_items, overflowing_literals, path_statements, patterns_in_fns_without_body, private_in_public, unconditional_recursion, unused, unused_allocation, unused_comparisons, unused_parens, while_true )] use std::fmt; use serde::{ ser::{SerializeMap, SerializeSeq, SerializeStruct, SerializeTupleStruct, Serializer}, Serialize, }; use tracing_core::{ event::Event, field::{Field, FieldSet, Visit}, metadata::{Level, Metadata}, span::{Attributes, Id, Record}, }; pub mod fields; #[derive(Debug)] pub struct SerializeField(Field); impl Serialize for SerializeField { fn serialize(&self, serializer: S) -> Result where S: Serializer, { serializer.serialize_str(self.0.name()) } } #[derive(Debug)] pub struct SerializeFieldSet<'a>(&'a FieldSet); impl<'a> Serialize for SerializeFieldSet<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut seq = serializer.serialize_seq(Some(self.0.len()))?; for element in self.0 { seq.serialize_element(element.name())?; } seq.end() } } #[derive(Debug)] pub struct SerializeLevel<'a>(&'a Level); impl<'a> Serialize for SerializeLevel<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { if self.0 == &Level::ERROR { serializer.serialize_str("ERROR") } else if self.0 == &Level::WARN { serializer.serialize_str("WARN") } else if self.0 == &Level::INFO { serializer.serialize_str("INFO") } else if self.0 == &Level::DEBUG { serializer.serialize_str("DEBUG") } else if self.0 == &Level::TRACE { serializer.serialize_str("TRACE") } else { unreachable!() } } } #[derive(Debug)] pub struct SerializeId<'a>(&'a Id); impl<'a> Serialize for SerializeId<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut state = serializer.serialize_tuple_struct("Id", 1)?; state.serialize_field(&self.0.into_u64())?; state.end() } } #[derive(Debug)] pub struct SerializeMetadata<'a>(&'a Metadata<'a>); impl<'a> Serialize for SerializeMetadata<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut state = serializer.serialize_struct("Metadata", 9)?; state.serialize_field("name", self.0.name())?; state.serialize_field("target", self.0.target())?; state.serialize_field("level", &SerializeLevel(self.0.level()))?; state.serialize_field("module_path", &self.0.module_path())?; state.serialize_field("file", &self.0.file())?; state.serialize_field("line", &self.0.line())?; state.serialize_field("fields", &SerializeFieldSet(self.0.fields()))?; state.serialize_field("is_span", &self.0.is_span())?; state.serialize_field("is_event", &self.0.is_event())?; state.end() } } /// Implements `serde::Serialize` to write `Event` data to a serializer. #[derive(Debug)] pub struct SerializeEvent<'a>(&'a Event<'a>); impl<'a> Serialize for SerializeEvent<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut serializer = serializer.serialize_struct("Event", 2)?; serializer.serialize_field("metadata", &SerializeMetadata(self.0.metadata()))?; let mut visitor = SerdeStructVisitor { serializer, state: Ok(()), }; self.0.record(&mut visitor); visitor.finish() } } /// Implements `serde::Serialize` to write `Attributes` data to a serializer. #[derive(Debug)] pub struct SerializeAttributes<'a>(&'a Attributes<'a>); impl<'a> Serialize for SerializeAttributes<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let mut serializer = serializer.serialize_struct("Attributes", 3)?; serializer.serialize_field("metadata", &SerializeMetadata(self.0.metadata()))?; serializer.serialize_field("parent", &self.0.parent().map(SerializeId))?; serializer.serialize_field("is_root", &self.0.is_root())?; let mut visitor = SerdeStructVisitor { serializer, state: Ok(()), }; self.0.record(&mut visitor); visitor.finish() } } /// Implements `serde::Serialize` to write `Record` data to a serializer. #[derive(Debug)] pub struct SerializeRecord<'a>(&'a Record<'a>); impl<'a> Serialize for SerializeRecord<'a> { fn serialize(&self, serializer: S) -> Result where S: Serializer, { let serializer = serializer.serialize_map(None)?; let mut visitor = SerdeMapVisitor::new(serializer); self.0.record(&mut visitor); visitor.finish() } } /// Implements `tracing_core::field::Visit` for some `serde::ser::SerializeMap`. #[derive(Debug)] pub struct SerdeMapVisitor { serializer: S, state: Result<(), S::Error>, } impl SerdeMapVisitor where S: SerializeMap, { /// Create a new map visitor. pub fn new(serializer: S) -> Self { Self { serializer, state: Ok(()), } } /// Completes serializing the visited object, returning `Ok(())` if all /// fields were serialized correctly, or `Error(S::Error)` if a field could /// not be serialized. pub fn finish(self) -> Result { self.state?; self.serializer.end() } /// Completes serializing the visited object, returning ownership of the underlying serializer /// if all fields were serialized correctly, or `Err(S::Error)` if a field could not be /// serialized. pub fn take_serializer(self) -> Result { self.state?; Ok(self.serializer) } } impl Visit for SerdeMapVisitor where S: SerializeMap, { #[cfg(all(tracing_unstable, feature = "valuable"))] #[cfg_attr(docsrs, doc(cfg(all(tracing_unstable, feature = "valuable"))))] fn record_value(&mut self, field: &Field, value: valuable_crate::Value<'_>) { if self.state.is_ok() { self.state = self .serializer .serialize_entry(field.name(), &valuable_serde::Serializable::new(value)); } } fn record_bool(&mut self, field: &Field, value: bool) { // If previous fields serialized successfully, continue serializing, // otherwise, short-circuit and do nothing. if self.state.is_ok() { self.state = self.serializer.serialize_entry(field.name(), &value) } } fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { if self.state.is_ok() { self.state = self .serializer .serialize_entry(field.name(), &format_args!("{:?}", value)) } } fn record_u64(&mut self, field: &Field, value: u64) { if self.state.is_ok() { self.state = self.serializer.serialize_entry(field.name(), &value) } } fn record_i64(&mut self, field: &Field, value: i64) { if self.state.is_ok() { self.state = self.serializer.serialize_entry(field.name(), &value) } } fn record_f64(&mut self, field: &Field, value: f64) { if self.state.is_ok() { self.state = self.serializer.serialize_entry(field.name(), &value) } } fn record_str(&mut self, field: &Field, value: &str) { if self.state.is_ok() { self.state = self.serializer.serialize_entry(field.name(), &value) } } } /// Implements `tracing_core::field::Visit` for some `serde::ser::SerializeStruct`. #[derive(Debug)] pub struct SerdeStructVisitor { serializer: S, state: Result<(), S::Error>, } impl Visit for SerdeStructVisitor where S: SerializeStruct, { #[cfg(all(tracing_unstable, feature = "valuable"))] #[cfg_attr(docsrs, doc(cfg(all(tracing_unstable, feature = "valuable"))))] fn record_value(&mut self, field: &Field, value: valuable_crate::Value<'_>) { if self.state.is_ok() { self.state = self .serializer .serialize_field(field.name(), &valuable_serde::Serializable::new(value)); } } fn record_bool(&mut self, field: &Field, value: bool) { // If previous fields serialized successfully, continue serializing, // otherwise, short-circuit and do nothing. if self.state.is_ok() { self.state = self.serializer.serialize_field(field.name(), &value) } } fn record_debug(&mut self, field: &Field, value: &dyn fmt::Debug) { if self.state.is_ok() { self.state = self .serializer .serialize_field(field.name(), &format_args!("{:?}", value)) } } fn record_u64(&mut self, field: &Field, value: u64) { if self.state.is_ok() { self.state = self.serializer.serialize_field(field.name(), &value) } } fn record_i64(&mut self, field: &Field, value: i64) { if self.state.is_ok() { self.state = self.serializer.serialize_field(field.name(), &value) } } fn record_f64(&mut self, field: &Field, value: f64) { if self.state.is_ok() { self.state = self.serializer.serialize_field(field.name(), &value) } } fn record_str(&mut self, field: &Field, value: &str) { if self.state.is_ok() { self.state = self.serializer.serialize_field(field.name(), &value) } } } impl SerdeStructVisitor { /// Completes serializing the visited object, returning `Ok(())` if all /// fields were serialized correctly, or `Error(S::Error)` if a field could /// not be serialized. pub fn finish(self) -> Result { self.state?; self.serializer.end() } } pub trait AsSerde<'a>: self::sealed::Sealed { type Serializable: serde::Serialize + 'a; /// `as_serde` borrows a `tracing` value and returns the serialized value. fn as_serde(&'a self) -> Self::Serializable; } impl<'a> AsSerde<'a> for tracing_core::Metadata<'a> { type Serializable = SerializeMetadata<'a>; fn as_serde(&'a self) -> Self::Serializable { SerializeMetadata(self) } } impl<'a> AsSerde<'a> for tracing_core::Event<'a> { type Serializable = SerializeEvent<'a>; fn as_serde(&'a self) -> Self::Serializable { SerializeEvent(self) } } impl<'a> AsSerde<'a> for tracing_core::span::Attributes<'a> { type Serializable = SerializeAttributes<'a>; fn as_serde(&'a self) -> Self::Serializable { SerializeAttributes(self) } } impl<'a> AsSerde<'a> for tracing_core::span::Id { type Serializable = SerializeId<'a>; fn as_serde(&'a self) -> Self::Serializable { SerializeId(self) } } impl<'a> AsSerde<'a> for tracing_core::span::Record<'a> { type Serializable = SerializeRecord<'a>; fn as_serde(&'a self) -> Self::Serializable { SerializeRecord(self) } } impl<'a> AsSerde<'a> for Level { type Serializable = SerializeLevel<'a>; fn as_serde(&'a self) -> Self::Serializable { SerializeLevel(self) } } impl<'a> self::sealed::Sealed for Event<'a> {} impl<'a> self::sealed::Sealed for Attributes<'a> {} impl self::sealed::Sealed for Id {} impl self::sealed::Sealed for Level {} impl<'a> self::sealed::Sealed for Record<'a> {} impl<'a> self::sealed::Sealed for Metadata<'a> {} mod sealed { pub trait Sealed {} }