|
|
@ -137,6 +137,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
|
|
|
|
Here's a mutable slice:
|
|
|
|
Here's a mutable slice:
|
|
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
```rust
|
|
|
|
|
|
|
|
# fn main() {}
|
|
|
|
use std::mem;
|
|
|
|
use std::mem;
|
|
|
|
|
|
|
|
|
|
|
|
pub struct IterMut<'a, T: 'a>(&'a mut[T]);
|
|
|
|
pub struct IterMut<'a, T: 'a>(&'a mut[T]);
|
|
|
@ -170,6 +171,7 @@ impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
|
|
|
|
And here's a binary tree:
|
|
|
|
And here's a binary tree:
|
|
|
|
|
|
|
|
|
|
|
|
```rust
|
|
|
|
```rust
|
|
|
|
|
|
|
|
# fn main() {}
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
|
|
|
|
|
|
|
|
type Link<T> = Option<Box<Node<T>>>;
|
|
|
|
type Link<T> = Option<Box<Node<T>>>;
|
|
|
@ -262,7 +264,7 @@ impl<'a, T> Iterator for IterMut<'a, T> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
|
|
|
|
impl<'a, T> DoubleEndedIterator for IterMut<'a, T> {
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
|
|
fn next_back(&mut self) -> Option<Self::Item> {
|
|
|
|
loop {
|
|
|
|
loop {
|
|
|
|
match self.0.back_mut().and_then(|node_it| node_it.next_back()) {
|
|
|
|
match self.0.back_mut().and_then(|node_it| node_it.next_back()) {
|
|
|
|
Some(State::Elem(elem)) => return Some(elem),
|
|
|
|
Some(State::Elem(elem)) => return Some(elem),
|
|
|
|