Trait Collection

Source
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] where W: Widget
  • Arrays [W; N] where W: Widget and const N: usize
  • Vec<W> where W: Widget
  • The output of kas::collection!. This macro constructs an anonymous struct of widgets which implements Collection.

Required Associated Types§

Source

type Data

The associated data type

Required Methods§

Source

fn len(&self) -> usize

The number of widgets

Source

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Get a widget as a Layout

Source

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Get a widget as a mutable Layout

Source

fn for_node( &mut self, data: &Self::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Operate on a widget as a Node

Provided Methods§

Source

fn is_empty(&self) -> bool

True if the collection is empty

Source

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.

Source

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

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 an Equal element is found at index
  • Some(Err(index)) if no Equal element is found; in this case such an element could be inserted at index
  • None if Collection::get_layout returns None for some index less than Collection::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.

Implementations on Foreign Types§

Source§

impl<W: Widget> Collection for [W]

Source§

type Data = <W as Widget>::Data

Source§

fn len(&self) -> usize

Source§

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Source§

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Source§

fn for_node( &mut self, data: &W::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Source§

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

Source§

impl<W: Widget> Collection for Vec<(GridCellInfo, W)>

Source§

type Data = <W as Widget>::Data

Source§

fn len(&self) -> usize

Source§

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Source§

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Source§

fn for_node( &mut self, data: &W::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Source§

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

Source§

impl<W: Widget> Collection for Vec<W>

Source§

type Data = <W as Widget>::Data

Source§

fn len(&self) -> usize

Source§

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Source§

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Source§

fn for_node( &mut self, data: &W::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Source§

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

Source§

impl<W: Widget> Collection for [(GridCellInfo, W)]

Source§

type Data = <W as Widget>::Data

Source§

fn len(&self) -> usize

Source§

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Source§

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Source§

fn for_node( &mut self, data: &W::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Source§

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

Source§

impl<const N: usize, W: Widget> Collection for [W; N]

Source§

type Data = <W as Widget>::Data

Source§

fn len(&self) -> usize

Source§

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Source§

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Source§

fn for_node( &mut self, data: &W::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Source§

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

Source§

impl<const N: usize, W: Widget> Collection for [(GridCellInfo, W); N]

Source§

type Data = <W as Widget>::Data

Source§

fn len(&self) -> usize

Source§

fn get_layout(&self, index: usize) -> Option<&dyn Layout>

Source§

fn get_mut_layout(&mut self, index: usize) -> Option<&mut dyn Layout>

Source§

fn for_node( &mut self, data: &W::Data, index: usize, closure: Box<dyn FnOnce(Node<'_>) + '_>, )

Source§

fn binary_search_by<'a, F>(&'a self, f: F) -> Option<Result<usize, usize>>
where F: FnMut(&'a dyn Layout) -> Ordering,

Implementors§