pub trait Collection {
type Data;
// Required methods
fn len(&self) -> usize;
fn get_layout(&self, index: usize) -> Option<&dyn Layout>;
fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>;
fn for_node(
&mut self,
data: &Self::Data,
index: usize,
closure: Box<dyn FnOnce(Node<'_>) + '_>,
);
// Provided methods
fn is_empty(&self) -> bool { ... }
fn iter_layout(
&self,
range: impl RangeBounds<usize>,
) -> CollectionIterLayout<'_, Self> { ... }
fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> 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: Widget
andconst 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_layout(
&self,
range: impl RangeBounds<usize>,
) -> CollectionIterLayout<'_, Self>
fn iter_layout( &self, range: impl RangeBounds<usize>, ) -> CollectionIterLayout<'_, Self>
Iterate over elements as Layout
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 anEqual
element is found atindex
Some(Err(index))
if noEqual
element is found; in this case such an element could be inserted atindex
None
ifCollection::get_layout
returnsNone
for someindex
less 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.