pub trait Collection {
type Data;
// Required methods
fn len(&self) -> usize;
fn get_tile(&self, index: usize) -> Option<&dyn Tile>;
fn get_mut_tile(&mut self, index: usize) -> Option<&mut dyn Tile>;
fn child_node<'n>(
&'n mut self,
data: &'n Self::Data,
index: usize,
) -> Option<Node<'n>>;
// Provided methods
fn is_empty(&self) -> bool { ... }
fn iter_tile(
&self,
range: impl RangeBounds<usize>,
) -> CollectionIterTile<'_, Self> { ... }
fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Tile) -> Ordering { ... }
}Expand description
A collection of (child) widgets
Essentially, a Collection is a list of widgets. Notable implementations are:
- Slices
[W]whereW: Widget - Arrays
[W; N]whereW: Widgetandconst N: usize Vec<W>whereW: Widget- The output of
kas::collection!. This macro constructs an anonymous struct of widgets which implementsCollection.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn iter_tile(
&self,
range: impl RangeBounds<usize>,
) -> CollectionIterTile<'_, Self>
fn iter_tile( &self, range: impl RangeBounds<usize>, ) -> CollectionIterTile<'_, Self>
Iterate over elements as Tile items within range
Note: there is currently no mutable equivalent due to the streaming iterator problem.
Sourcefn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
Binary searches this collection with a comparator function.
Similar to slice::binary_search_by[<[()]>::binary_search_by], the
comparator function should return whether the element is Less than,
Equal to, or Greater than the desired target, and the collection
should be sorted by this comparator (if not, the result is meaningless).
Returns:
Some(Ok(index))if anEqualelement is found atindexSome(Err(index))if noEqualelement is found; in this case such an element could be inserted atindexNoneifCollection::get_tilereturnsNonefor someindexless thanCollection::len. This is an error case that should not occur.
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.