#non-empty #slice #non-zero #vector #no-std #package

no-std not_empty

Slices and vectors that are statically guaranteed to be not empty

4 releases

0.1.3 Sep 22, 2022
0.1.2 Sep 22, 2022
0.1.1 Sep 22, 2022
0.1.0 Sep 22, 2022

#2004 in Rust patterns

Download history 241/week @ 2024-07-19 382/week @ 2024-07-26 401/week @ 2024-08-02 178/week @ 2024-08-09 142/week @ 2024-08-16 144/week @ 2024-08-23 399/week @ 2024-08-30 237/week @ 2024-09-06 20/week @ 2024-09-13 90/week @ 2024-09-20 96/week @ 2024-09-27 81/week @ 2024-10-04 121/week @ 2024-10-11 183/week @ 2024-10-18 92/week @ 2024-10-25 102/week @ 2024-11-01

515 downloads per month

MIT/Apache

105KB
1.5K SLoC

not_empty

Slices and vectors that are statically guaranteed to be not empty.

Build Status Latest Version

This crate is particularly useful for various operations on slices or vectors that would otherwise return an option now return the value with no performance penalty.

Usage

This crate is on crates.io and can be used by adding not_empty to your dependencies in your project's Cargo.toml:

[dependencies]
not_empty = "0.1"

Documentation

View the full reference on docs.rs here.

Features

  • alloc enables the use of allocated types through the alloc crate.
  • serde enables the use of the serde crate to serialize and deserialize any not_empty types.
  • std enables the use of the standard library.

Note: A compiler error is thrown if both alloc and std features are enabled. Only choose up to one.

Only the std feature is enabled by default.

Motivation

There are other packages that solve this solution. When searching for my own, I primarily came across two other packages:

  • nonempty which only supported vectors and didn't have a solution to working elegantly with iterators. Also, interoperability between its exported NonEmpty type and other slices or vectors left much to be desired from an architectural support. To be pedantic, I was jaded that the NonEmpty type was larger than a standard vector for non-zero sized types.
  • non-empty-vec did not enlarge the type, which was good, but it did not meet my needs for interoperability as well.

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~160KB