devtools_wire_format/
common.rs1mod generated {
2 #![allow(warnings)]
3 #![allow(clippy::all, clippy::pedantic)]
4 include!("./generated/rs.devtools.common.rs");
5}
6
7pub use generated::*;
8
9impl From<tracing_core::Level> for metadata::Level {
10 fn from(level: tracing_core::Level) -> Self {
11 match level {
12 tracing_core::Level::ERROR => metadata::Level::Error,
13 tracing_core::Level::WARN => metadata::Level::Warn,
14 tracing_core::Level::INFO => metadata::Level::Info,
15 tracing_core::Level::DEBUG => metadata::Level::Debug,
16 tracing_core::Level::TRACE => metadata::Level::Trace,
17 }
18 }
19}
20
21impl From<tracing_core::metadata::Kind> for metadata::Kind {
22 fn from(kind: tracing_core::metadata::Kind) -> Self {
23 match kind {
24 tracing_core::metadata::Kind::SPAN => metadata::Kind::Span,
25 tracing_core::metadata::Kind::EVENT => metadata::Kind::Event,
26 _ => panic!(),
27 }
28 }
29}
30
31impl<'a> From<&'a tracing_core::Metadata<'a>> for Metadata {
32 fn from(meta: &'a tracing_core::Metadata<'a>) -> Self {
33 let kind = if meta.is_span() {
34 metadata::Kind::Span
35 } else {
36 metadata::Kind::Event
37 };
38
39 let field_names = meta.fields().iter().map(|f| f.name().to_string()).collect();
40 Metadata {
41 name: meta.name().to_string(),
42 target: meta.target().to_string(),
43 location: Some(meta.into()),
44 kind: kind as i32,
45 level: metadata::Level::from(*meta.level()) as i32,
46 field_names,
47 }
48 }
49}
50
51impl From<&'static tracing_core::Metadata<'static>> for NewMetadata {
52 fn from(value: &'static tracing_core::Metadata<'static>) -> Self {
53 NewMetadata {
54 id: Some(std::ptr::from_ref(value) as u64),
55 metadata: Some(value.into()),
56 }
57 }
58}
59
60impl<'a> From<&'a tracing_core::Metadata<'a>> for Location {
61 fn from(meta: &'a tracing_core::Metadata<'a>) -> Self {
62 Location {
63 file: meta.file().map(String::from),
64 module_path: meta.module_path().map(String::from),
65 line: meta.line(),
66 column: None, }
68 }
69}
70
71impl<'a> From<&'a std::panic::Location<'a>> for Location {
72 fn from(loc: &'a std::panic::Location<'a>) -> Self {
73 Location {
74 file: Some(loc.file().to_string()),
75 module_path: None,
76 line: Some(loc.line()),
77 column: Some(loc.column()),
78 }
79 }
80}
81
82impl From<i64> for field::Value {
83 fn from(val: i64) -> Self {
84 field::Value::I64Val(val)
85 }
86}
87
88impl From<u64> for field::Value {
89 fn from(val: u64) -> Self {
90 field::Value::U64Val(val)
91 }
92}
93
94impl From<f64> for field::Value {
95 fn from(val: f64) -> Self {
96 field::Value::DoubleVal(val)
97 }
98}
99
100impl From<bool> for field::Value {
101 fn from(val: bool) -> Self {
102 field::Value::BoolVal(val)
103 }
104}
105
106impl From<&str> for field::Value {
107 fn from(val: &str) -> Self {
108 field::Value::StrVal(val.into())
109 }
110}
111
112impl From<&dyn std::fmt::Debug> for field::Value {
113 fn from(val: &dyn std::fmt::Debug) -> Self {
114 field::Value::DebugVal(format!("{val:?}"))
115 }
116}