diff --git a/core/string/src/lib.rs b/core/string/src/lib.rs index eb206dfd92f..96653ed52b1 100644 --- a/core/string/src/lib.rs +++ b/core/string/src/lib.rs @@ -36,6 +36,7 @@ pub use crate::{ iter::Iter, str::{JsStr, JsStrVariant}, }; +use std::borrow::Cow; use std::fmt::Write; use std::{ alloc::{alloc, dealloc, Layout}, @@ -982,6 +983,7 @@ impl From<&[JsString]> for JsString { ) } } + impl From for JsString { #[inline] fn from(s: String) -> Self { @@ -989,6 +991,16 @@ impl From for JsString { } } +impl<'a> From> for JsString { + #[inline] + fn from(s: Cow<'a, str>) -> Self { + match s { + Cow::Borrowed(s) => s.into(), + Cow::Owned(s) => s.into(), + } + } +} + impl From<&[u16; N]> for JsString { #[inline] fn from(s: &[u16; N]) -> Self {