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
2 changes: 1 addition & 1 deletion crates/oxc_span/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ compact_str = { workspace = true }
miette = { workspace = true }

schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"], optional = true }
serde = { workspace = true, optional = true }

[features]
default = []
Expand Down
11 changes: 9 additions & 2 deletions crates/oxc_span/src/compact_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{

use compact_str::CompactString;
#[cfg(feature = "serialize")]
use serde::{Serialize, Serializer};
use serde::{Deserialize, Deserializer, Serialize, Serializer};

use crate::Span;

Expand All @@ -21,7 +21,6 @@ pub const MAX_INLINE_LEN: usize = 16;
/// Currently implemented as just a wrapper around [`compact_str::CompactString`],
/// but will be reduced in size with a custom implementation later.
#[derive(Clone, Eq, PartialOrd, Ord)]
#[cfg_attr(feature = "serialize", derive(serde::Deserialize))]
pub struct CompactStr(CompactString);

impl CompactStr {
Expand Down Expand Up @@ -229,6 +228,14 @@ impl Serialize for CompactStr {
}
}

#[cfg(feature = "serialize")]
impl<'de> Deserialize<'de> for CompactStr {
fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
let compact_string = CompactString::deserialize(deserializer)?;
Ok(Self(compact_string))
}
}

#[cfg(feature = "schemars")]
impl schemars::JsonSchema for CompactStr {
fn is_referenceable() -> bool {
Expand Down
Loading