Skip to content

Commit

Permalink
Make SerializableNonZeroU64 deserializable
Browse files Browse the repository at this point in the history
  • Loading branch information
aqrln committed Nov 21, 2024
1 parent a33000a commit cb27a06
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion libs/telemetry/src/capturing/ng/collector.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::{borrow::Cow, collections::HashMap, num::NonZeroU64, sync::Arc};

use serde::Serialize;
use serde::{Deserialize, Serialize};
use tokio::time::Instant;
use tracing::Level;

Expand All @@ -21,6 +21,19 @@ impl Serialize for SerializableNonZeroU64 {
}
}

impl<'de> Deserialize<'de> for SerializableNonZeroU64 {
fn deserialize<D>(deserializer: D) -> Result<SerializableNonZeroU64, D::Error>
where
D: serde::Deserializer<'de>,
{
let value = String::deserialize(deserializer)?;
let value = value.parse().map_err(serde::de::Error::custom)?;
Ok(SerializableNonZeroU64(
NonZeroU64::new(value).ok_or_else(|| serde::de::Error::custom("value must be non-zero"))?,
))
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize)]
pub struct SpanId(SerializableNonZeroU64);

Expand Down

0 comments on commit cb27a06

Please sign in to comment.