oom - One Or Many slice types
Took inspirations from the "Parse, don’t validate" article.
This package defines two types: NonEmptySlice and NonEmptyMutSlice.
Note that those types are borrow types (not owned type). So you cannot
use them without borrow contents from array, slice or Vec.
Those types don't implement trait Deref or DerefMut, it is intentional to
avoid confusion when resolving methods. If you want &[T], consider using
as_slice or as_mut_slice.
Perhaps maybe in the future we will have NonEmptyVec, but
there are design questions about semantics when vec.pop().
The size of NonEmptySlice and NonEmptyMutSlice are the same as &[T].
The differences from &[T]:
.len()returns std'sNonZeroUsize..is_empty()is always false.- These methods don't return
None:firstfirst_mutlastlast_mutsplit_firstsplit_lastsplit_first_mutsplit_last_mut
Notable features
#![no_std]- no external dependencies
- no macros
- instant build time.
Supported Rust versions
Latest stable. Although I don't use new really new shiny features, but I don't build on older Rust stable versions so you should test it yourself.
Usage
Add this to your Cargo.toml:
[]
= "0.0.1"
Or assuming you installed cargo-edit, use:
cargo add oom
Thanks for inspirations from
- https://github.com/cloudhead/nonempty (MIT license)
- https://github.com/yihuang/non-empty-vec (MIT license)
License
All the code in this repository is released under the MIT License, for more information read the COPYRIGHT file.