Mitsein is a Rust library that provides strongly typed APIs for non-empty collections and views, including (but not limited to) iterators, slices, and vectors.
Basic Usage
Allocating a Vec1 from one or more items (infallibly):
use ;
let xs = from_item;
let xs = from;
let xs = from_head_and_tail;
let xs = vec1!;
Allocating a Vec1 from zero or more items (fallibly):
use Vec1;
let ys = vec!;
let xs = try_from?;
let xs = try_from?;
let xs = try_from_iter?;
Mapping over items in Vec1s:
use *;
use Vec1;
let xs = from;
let ys: = xs.into_iter1.map.collect;
Features and Comparisons
By providing non-empty APIs over both collections and views (i.e., slices
and iterators), Mitsein separates concerns just like standard collection and
iterator APIs. Unlike many other non-empty collection implementations, Mitsein
need not expose combinatorial sets of inherent iterator-like functions in
collections for each pair of receiver and operation. For example, the vec1
crate supports map operations over its Vec1 type via the Vec1::mapped,
Vec1::mapped_ref, and Vec1::mapped_mut functions. Mitsein instead exposes
map operations via Iterator1, which can support any non-empty view or
collection with a more typical API.
Non-empty view APIs also enable borrowing, so Mitsein collection types support
copy-on-write via the standard Cow type, unlike many other non-empty
collection implementations.
Non-empty iterator APIs are largely compatible with standard iterators, allowing non-empty collections to interact ergonomically with collection of zero or more items. Mitsein views and collections use more familiar syntax for mapping, taking, chaining, etc.
Items are stored contiguously or otherwise in a homogeneous manner in
Mitsein. This means that no head item is allocated diffently. For example, the
nonempty crate directly exposes a head item that is, unlike tail items,
not allocated on the heap. This can potentially cause surprising or poor
performance when the item type is large, as the head item is stack allocated.