Trait UnsafeIterator
pub trait UnsafeIterator {
type Item<'a>
where Self: 'a;
// Required method
unsafe fn next(&mut self) -> Result<Option<Self::Item<'_>>, Error>;
}Expand description
Trait used for iterating over iterators returned by Kanzi.
Note that next method is unsafe, since we cannot statically ensure that a given iterator
wasn’t invalidated by underlying collection modifications.
let mut iter = screen.get_children_iterator()?;
// SAFETY: Children are not being inserted or deleted from the underlying colleciton.
while let Some(child) = unsafe { iter.next() }? {
let parent = child.get_parent()?.into_error(ErrorKind::ObjectNotFound)?;
assert_eq!(parent, screen);
}To provide safe (albeit slower) alternatives all functions returning iterators also have a
‘pair’ function, which will eagerly call next and return the whole iterator.
// Note that this will eagerly store all children and will iterate only after that.
for child in screen.get_children()? {
let parent = child.get_parent()?.into_error(ErrorKind::ObjectNotFound)?;
assert_eq!(parent, screen);
}Required Associated Types§
type Item<'a> where Self: 'a
Required Methods§
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.