From 63e4364102fba7c253233ef1fde8d9f1c2c4e05f Mon Sep 17 00:00:00 2001 From: Joshix Date: Fri, 12 Sep 2025 17:00:00 +0000 Subject: [PATCH 1/2] implement Into> --- src/string.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/string.rs b/src/string.rs index 907dee1..9b60be7 100644 --- a/src/string.rs +++ b/src/string.rs @@ -315,12 +315,18 @@ impl From for FixedString { } impl From> for String { + fn from(value: FixedString) -> Self { + Box::::from(value).into() + } +} + +impl From> for Box { fn from(value: FixedString) -> 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()) }, } } } From 15780639d4919ff6e7d1fec1239842d4557adcf9 Mon Sep 17 00:00:00 2001 From: Joshix Date: Fri, 12 Sep 2025 17:00:00 +0000 Subject: [PATCH 2/2] remove unused import --- src/string.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string.rs b/src/string.rs index 9b60be7..be868ff 100644 --- a/src/string.rs +++ b/src/string.rs @@ -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};