#! @file iterable.sakura #! @author John Christman (sorakatadzuma@gmail.com) #! @copyright Malunal Studios, LLC. #! @license MIT #! #! Contains the iterable trait, which lends an iterator over the elements a #! container holds, and which a `for` loop walks. module core; #! Lends an iterator over the elements it holds, as references to them. #! #! `for x in c` calls `iter(&this)` once and walks what it gives, copying each #! element, and `for &x in c` refers to each instead. `for &mut x in c` calls #! `iter(&mut this)`, which a container whose elements may be changed in place #! gives, and which one that only reads leaves out. What `iter` gives is closed #! where the loop ends, however it ends, where it is `owning`. #! #! The iterator types are asked of the container, as `type list::cursor = #! ...;`, so generic code names them through a bound, as `C::cursor` where `C: #! iterable`. #! @tparam T The type of the elements, which the iterators give references to. pub trait iterable { #! What `iter(&this)` gives, which gives references that read the elements. type cursor: iterator<&T>; #! What `iter(&mut this)` gives, which gives references that write them. @optional type mut_cursor: iterator<&mut T>; #! Lends an iterator that reads the elements. #! @param this The container to iterate. #! @returns The iterator, which refers into the container. def iter(&this): cursor; #! Lends an iterator that writes the elements where they are. #! @param this The container to iterate. #! @returns The iterator, which refers into the container. @optional def iter(&mut this): mut_cursor; }