#options #collection #items #ordered #zero #enums #ot

zot

Provides Option-like enums for working with ordered collections of zero, one, or two items (Zot), or ordered collections of one or two items (Ot)

1 unstable release

0.1.0 Apr 8, 2021

#1428 in Data structures

Download history 31/week @ 2024-04-08 16/week @ 2024-04-15 28/week @ 2024-04-22 47/week @ 2024-04-29 23/week @ 2024-05-06 39/week @ 2024-05-13 48/week @ 2024-05-20 33/week @ 2024-05-27 26/week @ 2024-06-03 26/week @ 2024-06-10 30/week @ 2024-06-17 48/week @ 2024-06-24 13/week @ 2024-07-08 29/week @ 2024-07-15 33/week @ 2024-07-22

80 downloads per month
Used in 2 crates (via triangulate)

MIT/Apache

64KB
927 lines

Zot

Provides Option-like enums for working with ordered collections of zero, one, or two items (Zot), or ordered collections of one or two items (Ot).

let zot = Zot::Two("one", "two");
assert_eq!(zot.last(), Some("two"));
let ot = Ot::One("just one");
assert!(ot.is_one());

Most functionality mimics Option with a few exceptions:

  • Some new functions relating to the relative positions have been added:
    • first gets the singular element from *::One or the first element from *::Two. Zot<T> returns an Option<T>, with Zot::Zero returning None.
    • second gets the second element from *::Two. Both Ot<T> and Zot<T> return an Option<T>.
    • last gets the second element from *::Two or the singular element from *::One. Zot<T> returns an Option<T>, Ot<T> returns a T.
    • *_mut, replace_*, and take_* (Zot only) variations are also included.
  • Some functions which don't have a clear analogue when working with 2 values are not included (e.g. zip).
  • map requires a FnMut parameter instead of FnOnce as the function may need to be called twice.

Dependencies

~165KB