Skip to content
Merged
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
14 changes: 10 additions & 4 deletions src/string.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use alloc::{
borrow::{Cow, ToOwned},
boxed::Box,
string::{String, ToString},
string::{String},
sync::Arc,
};
use core::{borrow::Borrow, fmt::Write as _, hash::Hash, str::FromStr};
Expand Down Expand Up @@ -315,12 +315,18 @@ impl<LenT: ValidLength> From<char> for FixedString<LenT> {
}

impl<LenT: ValidLength> From<FixedString<LenT>> for String {
fn from(value: FixedString<LenT>) -> Self {
Box::<str>::from(value).into()
}
}

impl<LenT: ValidLength> From<FixedString<LenT>> for Box<str> {
fn from(value: FixedString<LenT>) -> Self {
match value.0 {
FixedStringRepr::Inline(a) => a.as_str().into(),
FixedStringRepr::Static(a) => a.as_str().into(),
// SAFETY: Self holds the type invariant that the array is UTF-8.
FixedStringRepr::Heap(a) => unsafe { String::from_utf8_unchecked(a.into()) },
FixedStringRepr::Inline(a) => a.as_str().to_string(),
FixedStringRepr::Static(a) => a.as_str().to_string(),
FixedStringRepr::Heap(a) => unsafe { alloc::str::from_boxed_utf8_unchecked(a.into()) },
}
}
}
Expand Down