pub struct BoundedListNode { /* private fields */ }
Expand description
This struct is intended to represent a list node in Inspect, which doesn’t support list natively. Furthermore, it makes sure that the number of items does not exceed |capacity|
Each item in BoundedListNode
is represented as a child node with name as index. This
index is always increasing and does not wrap around. For example, if capacity is 3,
then the children names are [0, 1, 2]
on first three addition. When a new node is
added, 0
is popped, and the children names are [1, 2, 3]
.
Implementations§
Source§impl BoundedListNode
impl BoundedListNode
Sourcepub fn new(node: Node, capacity: usize) -> Self
pub fn new(node: Node, capacity: usize) -> Self
Create a new BoundedListNode with capacity 1 or |capacity|, whichever is larger.
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the capacity of the BoundedListNode
, the maximum number of child nodes.
Sourcepub fn add_entry<F>(&mut self, initialize: F) -> &Nodewhere
F: FnOnce(&Node),
pub fn add_entry<F>(&mut self, initialize: F) -> &Nodewhere
F: FnOnce(&Node),
Create a new entry within a list and return a writer that creates properties or children for this entry. The writer does not have to be kept for the created properties and children to be maintained in the list.
If creating new entry exceeds capacity of the list, the oldest entry is evicted.
The initialize
function will be used to atomically initialize all children and properties
under the node.