Skip to content

Commit

Permalink
chore: limit the generic type D of JsStringBuilder to Copy
Browse files Browse the repository at this point in the history
  • Loading branch information
CrazyboyQCD committed Nov 14, 2024
1 parent e8f9f3b commit 61fe735
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions core/string/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ use std::{
/// A mutable builder to create instance of `JsString`.
///
#[derive(Debug)]
pub struct JsStringBuilder<D> {
pub struct JsStringBuilder<D: Copy> {
cap: usize,
len: usize,
inner: NonNull<RawJsString>,
phantom_data: PhantomData<D>,
}

impl<D> Clone for JsStringBuilder<D> {
impl<D: Copy> Clone for JsStringBuilder<D> {
#[inline]
#[must_use]
fn clone(&self) -> Self {
Expand All @@ -45,13 +45,13 @@ impl<D> Clone for JsStringBuilder<D> {
}
}

impl<D> Default for JsStringBuilder<D> {
impl<D: Copy> Default for JsStringBuilder<D> {
fn default() -> Self {
Self::new()
}
}

impl<D> JsStringBuilder<D> {
impl<D: Copy> JsStringBuilder<D> {
const DATA_SIZE: usize = size_of::<D>();
const MIN_NON_ZERO_CAP: usize = 8 / Self::DATA_SIZE;

Expand Down Expand Up @@ -412,7 +412,7 @@ impl<D> JsStringBuilder<D> {
}
}

impl<D> Drop for JsStringBuilder<D> {
impl<D: Copy> Drop for JsStringBuilder<D> {
/// Set cold since [`JsStringBuilder`] should be created to build `JsString`
#[cold]
#[inline]
Expand All @@ -432,19 +432,19 @@ impl<D> Drop for JsStringBuilder<D> {
}
}

impl<D> AddAssign<&JsStringBuilder<D>> for JsStringBuilder<D> {
impl<D: Copy> AddAssign<&JsStringBuilder<D>> for JsStringBuilder<D> {
fn add_assign(&mut self, rhs: &JsStringBuilder<D>) {
self.extend_from_slice(rhs.as_slice());
}
}

impl<D> AddAssign<&[D]> for JsStringBuilder<D> {
impl<D: Copy> AddAssign<&[D]> for JsStringBuilder<D> {
fn add_assign(&mut self, rhs: &[D]) {
self.extend_from_slice(rhs);
}
}

impl<D> FromIterator<D> for JsStringBuilder<D> {
impl<D: Copy> FromIterator<D> for JsStringBuilder<D> {
fn from_iter<T: IntoIterator<Item = D>>(iter: T) -> Self {
let mut builder = Self::new();
builder.extend(iter);
Expand Down

0 comments on commit 61fe735

Please sign in to comment.