Skip to content

Commit

Permalink
feat(span): add CompactStr::to_compact_string method
Browse files Browse the repository at this point in the history
For cases where we want to get the inner string and mutate it.
  • Loading branch information
Boshen committed Sep 1, 2024
1 parent 29f8497 commit 060e843
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions crates/oxc_span/src/atom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,12 @@ impl CompactStr {
self.0.into_string()
}

/// Convert a [`CompactStr`] into a [`CompactString`].
#[inline]
pub fn into_compact_string(self) -> CompactString {
self.0
}

/// Get length of [`CompactStr`].
///
/// # Examples
Expand Down Expand Up @@ -420,6 +426,7 @@ impl schemars::JsonSchema for CompactStr {
#[cfg(test)]
mod test {
use super::CompactStr;
use compact_str::CompactString;

#[test]
fn test_compactstr_eq() {
Expand All @@ -428,5 +435,6 @@ mod test {
assert_eq!(&foo, "foo");
assert_eq!("foo", foo);
assert_eq!("foo", &foo);
assert_eq!(foo.into_compact_string(), CompactString::new("foo"));
}
}

0 comments on commit 060e843

Please sign in to comment.