Skip to content

Commit

Permalink
Add From<Cow<'a, str>> for JsString (#4134)
Browse files Browse the repository at this point in the history
* chore: add `From<Cow<'a, str>>` for `JsString`

* chore: marked as inline
  • Loading branch information
CrazyboyQCD authored Jan 15, 2025
1 parent f64d937 commit c48056e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/string/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -982,13 +983,24 @@ impl From<&[JsString]> for JsString {
)
}
}

impl From<String> for JsString {
#[inline]
fn from(s: String) -> Self {
Self::from(s.as_str())
}
}

impl<'a> From<Cow<'a, str>> for JsString {
#[inline]
fn from(s: Cow<'a, str>) -> Self {
match s {
Cow::Borrowed(s) => s.into(),
Cow::Owned(s) => s.into(),
}
}
}

impl<const N: usize> From<&[u16; N]> for JsString {
#[inline]
fn from(s: &[u16; N]) -> Self {
Expand Down

0 comments on commit c48056e

Please sign in to comment.