# Advantages to implementing \`FusedIterator\` on non-public type

**URL:** <https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015>\
**Category:** help\
**Created:** [May 9, 2026, 5:17pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015 "2026-05-09T17:17:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhpratt](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jhpratt/32/37974_2.png) [@jhpratt](https://users.rust-lang.org/u/jhpratt)\
**Post date:** [May 9, 2026, 5:17pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/1 "2026-05-09T17:17:25Z")

</div>

For an iterator that I'm implementing and is strictly internal, is there any advantage to implementing `FusedIterator`? I don't ever call `fuse`, nor do I rely on it in any way. I don't believe the standard library uses specialization for anything on this, but I could be wrong.

Edit: On second thought, the standard library _can't_ use specialization here because it's not an `unsafe` trait, so any optimization based on it would be unsound…

---

<div class="post-metadata">

**Author:** ![conqp](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/conqp/32/42559_2.png) [@conqp](https://users.rust-lang.org/u/conqp)\
**Post date:** [May 9, 2026, 6:14pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/2 "2026-05-09T18:14:35Z")

</div>

I'd say that it depends. If the type behaves like a fused iterator and you need to rely on this fact, you should implement it, since it nicely documents this iterators property.  
If the iterator does only incidentally behave this way and you don't rely on this property, it may not be worth the extra impl block.  
On the other hand, I'd always implement it for types which are exported by a library, because

> This trait should be implemented by all iterators that behave this way because it allows optimizing [`Iterator::fuse()`](https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fuse).

> **[FusedIterator in std::iter - Rust](https://doc.rust-lang.org/std/iter/trait.FusedIterator.html)**
>
> An iterator that always continues to yield \`None\` when exhausted.

So I'd implement it if, and only if

- I'd rely on the fact that the iterator is fused, even if it's only used internally, or
- If the iterator has any chance of one day being exported from the library.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jhpratt/32/37974_2.png) [@jhpratt](https://users.rust-lang.org/u/jhpratt)\
**Post date:** [May 9, 2026, 6:21pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/3 "2026-05-09T18:21:29Z")

</div>

Zero chance of it ever being exported. My post wasn't 100% clear, when I say "advantages" I was referring to technical advantages, such as the possibility of optimization.

---

<div class="post-metadata">

**Author:** ![conqp](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/conqp/32/42559_2.png) [@conqp](https://users.rust-lang.org/u/conqp)\
**Post date:** [May 9, 2026, 6:25pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/4 "2026-05-09T18:25:06Z")

</div>

If you use the iterator internally with standard library tools, which use `Iterator::fuse`, then, yes, you could benefit from optimizations.  
If you just use the iterator in a `for` loop, then no, there's no benefit in implementing it.

**Edit** FWIW:

```rust
~/Projekte/rust/library> grep -rE '\.fuse\(|::fuse\('
alloctests/benches/vec.rs: .fuse()
std/src/sys/pal/unix/conf.rs: let mut parsed_ints = version.split('.').map(str::parse::<usize>).fuse();
core/src/iter/traits/marker.rs:/// that behave this way because it allows optimizing [`Iterator::fuse()`].
core/src/iter/traits/marker.rs:/// you need a fused iterator. Instead, you should just call [`Iterator::fuse()`]
core/src/iter/traits/iterator.rs: /// let mut iter = iter.fuse();
core/src/iter/adapters/fuse.rs: /// This is equivalent to `I::default().fuse()`[^fuse_note]; e.g. if
core/src/iter/adapters/flatten.rs: FlattenCompat { iter: iter.fuse(), frontiter: None, backiter: None }
coretests/tests/iter/adapters/fuse.rs: let i = it.fuse().fold(0, |i, &x| {
coretests/tests/iter/adapters/fuse.rs: let i = it.fuse().rfold(xs.len(), |i, &x| {
coretests/tests/iter/adapters/fuse.rs: let i = it.fuse().fold(0, |i, x| {
coretests/benches/iter.rs: (0i64..1000000).fuse()
coretests/benches/iter.rs: (0i64..1000000).chain(0..1000000).fuse()
coretests/benches/iter.rs: .fuse();
~/Projekte/rust/library>                               

```

So I guess only `Iterator::flatten()` would benefit from this.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/kpreid/32/22420_2.png) [@kpreid](https://users.rust-lang.org/u/kpreid)\
**Post date:** [May 9, 2026, 6:29pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/5 "2026-05-09T18:29:54Z")

</div>

> [@jhpratt](#):
>
> the standard library _can't_ use specialization here because it's not an `unsafe` trait, so any optimization based on it would be unsound…

Not every possible optimization has unsoundness as a consequence. Some might merely produce incorrect results.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/jhpratt/32/37974_2.png) [@jhpratt](https://users.rust-lang.org/u/jhpratt)\
**Post date:** [May 9, 2026, 6:37pm UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/6 "2026-05-09T18:37:07Z")

</div>

> [@conqp](#):
>
> If you just use the iterator in a `for` loop, then no, there's no benefit in implementing it.

That's effectively what I'm doing, just mapping and collecting afterwards.

> [@kpreid](#):
>
> Not every possible optimization has unsoundness as a consequence. Some might merely produce incorrect results

True. I'm thinking from my perspective as what the standard library tends to do (such as `TrustedLen`

---

<div class="post-metadata">

**Author:** ![Morgane55440](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/morgane55440/32/50376_2.png) [@Morgane55440](https://users.rust-lang.org/u/Morgane55440)\
**Post date:** [May 12, 2026, 8:51am UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/7 "2026-05-12T08:51:30Z")

</div>

> [@jhpratt](#):
>
> I don't believe the standard library uses specialization for anything on this, but I could be wrong.
> 
> Edit: On second thought, the standard library _can't_ use specialization here because it's not an `unsafe` trait, so any optimization based on it would be unsound…

[well you were wrong actually](https://goldstein.lol/posts/stable-specialization/).  
this is pretty to be fair, but they did do it

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [August 10, 2026, 8:51am UTC](https://users.rust-lang.org/t/advantages-to-implementing-fusediterator-on-non-public-type/140015/8 "2026-08-10T08:51:30Z")

</div>

Closed on August 10, 2026, 8:51am UTC

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.
