parallel_disk_usage/visualizer/child_position.rs
1use std::num::NonZeroUsize;
2
3/// Whether an item in [`children`](crate::data_tree::DataTree::children) is the last.
4#[derive(Debug, Clone, Copy, PartialEq, Eq)]
5pub enum ChildPosition {
6 /// The item is not the last child.
7 Init,
8 /// The item is the last child.
9 Last,
10}
11
12impl ChildPosition {
13 /// Deduce a child's position from its index and the number of children.
14 pub const fn from_index(child_index: usize, child_count: NonZeroUsize) -> Self {
15 if child_index + 1 < child_count.get() {
16 ChildPosition::Init
17 } else {
18 ChildPosition::Last
19 }
20 }
21}