Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions crates/oxc_span/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use oxc_allocator::{Allocator, CloneIn, FromIn};
#[cfg(feature = "serialize")]
use serde::Serialize;
use serde::{Serialize, Serializer};

use crate::{CompactStr, ContentEq};

Expand All @@ -15,8 +15,6 @@ use crate::{CompactStr, ContentEq};
/// Use [CompactStr] with [Atom::to_compact_str] or [Atom::into_compact_str] for
/// the lifetimeless form.
#[derive(Clone, Copy, Eq)]
#[cfg_attr(feature = "serialize", derive(Serialize))]
#[cfg_attr(feature = "serialize", serde(transparent))]
pub struct Atom<'a>(&'a str);

impl Atom<'static> {
Expand Down Expand Up @@ -207,3 +205,10 @@ impl fmt::Display for Atom<'_> {
fmt::Display::fmt(self.as_str(), f)
}
}

#[cfg(feature = "serialize")]
impl Serialize for Atom<'_> {
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.0.serialize(serializer)
}
}
7 changes: 2 additions & 5 deletions crates/oxc_span/src/compact_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,8 @@ impl fmt::Display for CompactStr {

#[cfg(feature = "serialize")]
impl Serialize for CompactStr {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where
S: Serializer,
{
serializer.serialize_str(self.as_str())
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
self.as_str().serialize(serializer)
}
}

Expand Down
Loading