Implement FusedIterator for NulTerminated, NulTerminatedInclusive

This commit is contained in:
Peter Limkilde Svendsen
2024-10-27 13:43:37 +00:00
committed by Jeremy Soller
parent 9fb744a9c0
commit d41ec992af
+14 -1
View File
@@ -1,6 +1,11 @@
//! Utilities to help use Rust iterators on C strings.
use core::{iter::Iterator, marker::PhantomData, mem::MaybeUninit, ptr::NonNull};
use core::{
iter::{FusedIterator, Iterator},
marker::PhantomData,
mem::MaybeUninit,
ptr::NonNull,
};
use crate::platform::types::*;
@@ -77,6 +82,10 @@ impl<'a, T: Zero> NulTerminated<'a, T> {
}
}
// Once the terminating nul has been encountered, the pointer will not advance
// further and the iterator will thus keep returning None.
impl<'a, T: Zero> FusedIterator for NulTerminated<'a, T> {}
/// An iterator over a nul-terminated buffer, including the terminating nul.
///
/// Similar to [`NulTerminated`], but includes the terminating nul.
@@ -130,6 +139,10 @@ impl<'a, T: Zero> NulTerminatedInclusive<'a, T> {
}
}
// Once the terminating nul has been encountered, the internal Option will be
// set to None, ensuring that we will keep returning None.
impl<'a, T: Zero> FusedIterator for NulTerminatedInclusive<'a, T> {}
/// A zipped iterator mapping an input iterator to an "out" pointer.
///
/// This is intended to allow safe, iterative writing to an "out pointer".