feat(span): add CompactStr::to_compact_string method (#5385)

For cases where we want to get the inner string and mutate it.
This commit is contained in:
Boshen 2024-09-01 10:49:39 +00:00
parent 29f8497001
commit 1b20ceb70c

View file

@ -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
@ -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() {
@ -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"));
}
}