From ef73fb65cb48745361a9428940feb799d5ad5c10 Mon Sep 17 00:00:00 2001 From: Oliver THEBAULT Date: Fri, 3 May 2024 16:20:43 +0200 Subject: [PATCH] feat: make serde_json/preserve_order feature optional --- Cargo.lock | 1 - Cargo.toml | 1 + test-span/Cargo.toml | 2 +- test-span/src/layer.rs | 8 ++++---- test-span/src/log.rs | 13 ++++++------- test-span/src/report.rs | 9 ++++----- 6 files changed, 16 insertions(+), 18 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index c5c4bad..a152179 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -485,7 +485,6 @@ version = "1.0.74" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee2bb9cd061c5865d345bb02ca49fcef1391741b672b54a0bf7b679badec3142" dependencies = [ - "indexmap", "itoa", "ryu", "serde", diff --git a/Cargo.toml b/Cargo.toml index 216fc8d..0ef9522 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,2 +1,3 @@ [workspace] +resolver = "2" members = ["test-span", "test-span-macro"] diff --git a/test-span/Cargo.toml b/test-span/Cargo.toml index 716e6e8..21671ff 100644 --- a/test-span/Cargo.toml +++ b/test-span/Cargo.toml @@ -15,7 +15,7 @@ license = "MIT OR Apache-2.0" [dependencies] daggy = { version = "0.8.0", features = ["serde-1", "stable_dag"] } serde = { version = "1.0.131", features = ["derive"] } -serde_json = { version = "1.0.72", features = ["preserve_order"] } +serde_json = "1.0.72" tokio = { version = "1.14.0", features = ["full"] } tracing = "0.1.29" tracing-futures = "0.2.5" diff --git a/test-span/src/layer.rs b/test-span/src/layer.rs index 40cde14..987e489 100644 --- a/test-span/src/layer.rs +++ b/test-span/src/layer.rs @@ -32,7 +32,7 @@ impl Layer { fn event(&self, event: &Event<'_>, ctx: Context<'_, impl tracing::Subscriber>) { let current_span = ctx.current_span(); - let current_span = current_span.id().map(std::clone::Clone::clone); + let current_span = current_span.id().cloned(); ALL_LOGS.lock().unwrap().event(current_span, event); } @@ -52,7 +52,7 @@ impl Layer { let (root_span_id, parent_node_index) = id_to_node_index .get(&raw_parent_id) - .map(std::clone::Clone::clone) + .copied() .unwrap_or_else(|| panic!("missing parent attributes for {}.", raw_parent_id)); let (_, node_index) = @@ -106,8 +106,8 @@ where ) { let maybe_parent_id = attrs .parent() - .map(std::clone::Clone::clone) - .or_else(|| ctx.current_span().id().map(std::clone::Clone::clone)); + .cloned() + .or_else(|| ctx.current_span().id().cloned()); self.attributes(id.clone(), attrs, maybe_parent_id) } diff --git a/test-span/src/log.rs b/test-span/src/log.rs index a5b827a..13fd2d4 100644 --- a/test-span/src/log.rs +++ b/test-span/src/log.rs @@ -46,21 +46,20 @@ impl LogsRecorder { ) -> Vec { self.recorders .iter() - .filter_map(|(log_metadata, recorders)| { - (filter.is_enabled(log_metadata) && log_metadata.span_id == Some(span_id)) - .then(|| recorders.contents().cloned()) + .filter(|(log_metadata, _recorders)| { + filter.is_enabled(log_metadata) && log_metadata.span_id == Some(span_id) }) - .flatten() + .flat_map(|(_log_metadata, recorders)| recorders.contents().cloned()) .collect() } pub fn all_records_for_filter(&self, filter: &crate::Filter) -> Vec { self.recorders .iter() - .filter_map(|(log_metadata, recorders)| { - (filter.is_enabled(log_metadata)).then(|| recorders.contents().cloned()) + .filter(|(log_metadata, _recorders)| { + filter.is_enabled(log_metadata) }) - .flatten() + .flat_map(|(_log_metadata, recorders)| recorders.contents().cloned()) .collect() } } diff --git a/test-span/src/report.rs b/test-span/src/report.rs index 5fc1aea..9037456 100644 --- a/test-span/src/report.rs +++ b/test-span/src/report.rs @@ -108,12 +108,13 @@ impl Report { let id_to_node = SPAN_ID_TO_ROOT_AND_NODE_INDEX.lock().unwrap().clone(); let (global_root, root_node_index) = id_to_node .get(&root_node) - .map(std::clone::Clone::clone) + .copied() .expect("couldn't find rood node"); let node_to_id: IndexMap = id_to_node .into_iter() - .filter_map(|(key, (root, value))| (root == global_root).then(|| (value, key))) + .filter(|&(_key, (root, _value))| root == global_root) + .map(|(key, (_root, value))| (value, key)) .collect(); let relevant_spans = node_to_id.values().cloned().collect::>(); @@ -165,8 +166,6 @@ impl Report { if let Some(recorder) = self.spans.get(&self.root_id) { let metadata = recorder .metadata() - .as_ref() - .map(std::clone::Clone::clone) .expect("recorder without metadata"); let span_name = format!("{}::{}", metadata.target, metadata.name); @@ -194,7 +193,7 @@ impl Report { .contents(filter); child_record.append(self.logs.record_for_span_id_and_filter(*child_id, filter)); - records.extend(child_record.entries().cloned().into_iter()); + records.extend(child_record.entries().cloned()); self.dfs_logs_insert(records, child_node, filter); } }