jamsocket / aper

A Rust data structure library built on state machines.
https://aper.dev
MIT License
299 stars 12 forks source link

Generalize relative/absolute `List` positions #14

Closed paulgb closed 3 years ago

paulgb commented 3 years ago

There are a number of ways to refer to a position in a List, which determines the behavior when the list has changed between when the reference is created and when it is used:

When adding an item in reference to another item, we usually want to fall back on a fractional index. That way, if the item it is in reference to is removed, we can fall back on the index.

For simplicity the right approach here is probably something like:

pub enum ListPosition {
    Beginning,
    End,
    AbsolutePosition(ZenoIndex),
    Before(Uuid, ZenoIndex),
    After(Uuid, ZenoIndex),
}

This would accomplish the most common use cases, but not the more complex ones.