File: README.md

package info (click to toggle)
rust-nonempty 0.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 156 kB
  • sloc: makefile: 2
file content (20 lines) | stat: -rw-r--r-- 460 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Correct by Construction Non-Empty List

This package exposes a type `NonEmpty<T>` with a data representation
that guarantees non-emptiness statically:

    struct NonEmpty<T>(T, Vec<T>)

The library is meant to have an interface similar to `std::vec::Vec`:

    use nonempty::NonEmpty;

    let mut l = NonEmpty::new(42);

    assert_eq!(l.first(), &42);

    l.push(36);
    l.push(58);

    let v: Vec<i32> = l.into();
    assert_eq!(v, vec![42, 36, 58]);