Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions library/alloc/src/string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2058,8 +2058,6 @@ impl String {
/// Basic usage:
///
/// ```
/// #![feature(string_into_chars)]
///
/// let word = String::from("goodbye");
///
/// let mut chars = word.into_chars();
Expand All @@ -2078,8 +2076,6 @@ impl String {
/// Remember, [`char`]s might not match your intuition about characters:
///
/// ```
/// #![feature(string_into_chars)]
///
/// let y = String::from("y̆");
///
/// let mut chars = y.into_chars();
Expand All @@ -2093,7 +2089,7 @@ impl String {
/// [`char`]: prim@char
#[inline]
#[must_use = "`self` will be dropped if the result is not used"]
#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
pub fn into_chars(self) -> IntoChars {
IntoChars { bytes: self.into_bytes().into_iter() }
}
Expand Down Expand Up @@ -3439,12 +3435,12 @@ impl fmt::Write for String {
/// [`into_chars`]: String::into_chars
#[cfg_attr(not(no_global_oom_handling), derive(Clone))]
#[must_use = "iterators are lazy and do nothing unless consumed"]
#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
pub struct IntoChars {
bytes: vec::IntoIter<u8>,
}
Comment on lines 3439 to 3441

@clarfonthey clarfonthey Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is just a wrapper over vec::IntoIter, we could pretty easily derive(Clone) and support it. I would say that's useful since cloning iterators is pretty useful for debugging, even if it would allocate a copy here.

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't it already have Clone?

#[cfg_attr(not(no_global_oom_handling), derive(Clone))]

Or did you mean that it should always derive(Clone)?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I totally missed that line. You just didn't include it in the public API in the description is why I was confused.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I just copied the output from cargo unstable-api which didn't include the clone 😅 It's probably because it was in #[cfg_attr].


#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
impl fmt::Debug for IntoChars {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_tuple("IntoChars").field(&self.as_str()).finish()
Expand All @@ -3457,8 +3453,6 @@ impl IntoChars {
/// # Examples
///
/// ```
/// #![feature(string_into_chars)]
///
/// let mut chars = String::from("abc").into_chars();
///
/// assert_eq!(chars.as_str(), "abc");
Expand All @@ -3468,7 +3462,7 @@ impl IntoChars {
/// chars.next();
/// assert_eq!(chars.as_str(), "");
/// ```
#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
#[must_use]
#[inline]
pub fn as_str(&self) -> &str {
Expand All @@ -3481,8 +3475,6 @@ impl IntoChars {
/// # Examples
///
/// ```
/// #![feature(string_into_chars)]
///
/// let chars = String::from("abc").into_chars();
/// assert_eq!(chars.into_string(), "abc");
///
Expand All @@ -3491,7 +3483,7 @@ impl IntoChars {
/// assert_eq!(chars.into_string(), "ef");
/// ```
#[cfg(not(no_global_oom_handling))]
#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
#[inline]
pub fn into_string(self) -> String {
// SAFETY: `bytes` are kept in UTF-8 form, only removing whole `char`s at a time.
Expand All @@ -3504,7 +3496,7 @@ impl IntoChars {
}
}

#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
impl Iterator for IntoChars {
type Item = char;

Expand Down Expand Up @@ -3538,7 +3530,7 @@ impl Iterator for IntoChars {
}
}

#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
impl DoubleEndedIterator for IntoChars {
#[inline]
fn next_back(&mut self) -> Option<char> {
Expand All @@ -3555,7 +3547,7 @@ impl DoubleEndedIterator for IntoChars {
}
}

#[unstable(feature = "string_into_chars", issue = "133125")]
#[stable(feature = "string_into_chars", since = "CURRENT_RUSTC_VERSION")]
impl FusedIterator for IntoChars {}

/// A draining iterator for `String`.
Expand Down
Loading