Skip to content

Commit

Permalink
Rollup merge of #96397 - AronParker:issue-96368-fix, r=dtolnay
Browse files Browse the repository at this point in the history
Make EncodeWide implement FusedIterator

[`EncodeUtf16`](https://doc.rust-lang.org/std/str/struct.EncodeUtf16.html) and [`EncodeWide`](https://doc.rust-lang.org/std/os/windows/ffi/struct.EncodeWide.html) currently serve similar purposes: They convert from UTF-8 to UTF-16 and WTF-8 to WTF-16, respectively. `EncodeUtf16` wraps a &str, whereas `EncodeWide` wraps an &OsStr.

When Iteration has concluded, these iterators wrap an empty slice, which will forever yield `None` values. Hence, `EncodeUtf16` rightfully implements `FusedIterator`. However, `EncodeWide` in contrast does not, even though it serves an almost identical purpose.

This PR attempts to fix that issue. I consider this change minor and non-controversial, hence why I have not added a RFC/FCP. Please let me know if the stability attribute is wrong or contains a wrong version number. Thanks in advance.

Fixes #96368
  • Loading branch information
Dylan-DPC committed Apr 28, 2022
2 parents 4a7483c + fc6af81 commit c4dd0d3
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion library/std/src/sys_common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use crate::char;
use crate::collections::TryReserveError;
use crate::fmt;
use crate::hash::{Hash, Hasher};
use crate::iter::FromIterator;
use crate::iter::{FromIterator, FusedIterator};
use crate::mem;
use crate::ops;
use crate::rc::Rc;
Expand Down Expand Up @@ -899,6 +899,9 @@ impl<'a> Iterator for EncodeWide<'a> {
}
}

#[stable(feature = "encode_wide_fused_iterator", since = "1.62.0")]
impl FusedIterator for EncodeWide<'_> {}

impl Hash for CodePoint {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
Expand Down

0 comments on commit c4dd0d3

Please sign in to comment.