Skip to content

Commit

Permalink
serialize tagsets more directly for more native output structure
Browse files Browse the repository at this point in the history
  • Loading branch information
tobz committed Jan 29, 2025
1 parent 4ce4d0e commit 4a44bc1
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/saluki-context/src/tags/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use std::{fmt, hash, ops::Deref as _, sync::Arc};

use serde::Serialize;
use stringtheory::MetaString;

mod raw;
Expand Down Expand Up @@ -89,6 +90,15 @@ impl fmt::Display for Tag {
}
}

impl Serialize for Tag {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(&self.0)
}
}

impl<T> From<T> for Tag
where
T: Into<MetaString>,
Expand Down Expand Up @@ -180,7 +190,7 @@ impl<'a> hash::Hash for BorrowedTag<'a> {
}

/// A set of tags.
#[derive(Clone, Debug, Default)]
#[derive(Clone, Debug, Default, Serialize)]
pub struct TagSet(Vec<Tag>);

impl TagSet {
Expand Down Expand Up @@ -482,14 +492,12 @@ impl fmt::Display for SharedTagSet {
}
}

impl serde::Serialize for SharedTagSet {
impl Serialize for SharedTagSet {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
// We have this manual implementation of `Serialize` just to avoid needing to bring in `serde_with` to get the
// helper that utilizes the `Display` implementation.
serializer.collect_str(self)
self.0.deref().serialize(serializer)
}
}

Expand Down

0 comments on commit 4a44bc1

Please sign in to comment.