From d4c064c92e4a01a9ebe258cfeaa8a0b3858b70c7 Mon Sep 17 00:00:00 2001 From: pantonshire Date: Thu, 8 Sep 2022 13:34:37 +0100 Subject: [PATCH] Conversions between CappedString and Box --- src/strings/capped.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/strings/capped.rs b/src/strings/capped.rs index 25bf6cc..fc06a18 100644 --- a/src/strings/capped.rs +++ b/src/strings/capped.rs @@ -199,6 +199,16 @@ impl TryFrom for CappedString { } } +#[cfg(feature = "alloc")] +impl TryFrom> for CappedString { + type Error = Error; + + #[inline] + fn try_from(s: Box) -> Result { + Self::new(&s) + } +} + #[cfg(feature = "alloc")] impl<'a, const N: usize> TryFrom> for CappedString { type Error = Error; @@ -217,6 +227,14 @@ impl From> for String { } } +#[cfg(feature = "alloc")] +impl From> for Box { + #[inline] + fn from(s: CappedString) -> Self { + s.into_boxed_str() + } +} + impl PartialEq> for CappedString { #[inline] fn eq(&self, other: &CappedString) -> bool {