Debian Codegraph @

third_party/rust/tinyvec/README.md

raw
1 [![License:Zlib](https://img.shields.io/badge/License-Zlib-brightgreen.svg)](https://opensource.org/licenses/Zlib)
2 ![Minimum Rust Version](https://img.shields.io/badge/Min%20Rust-1.47-green.svg)
3 [![crates.io](https://img.shields.io/crates/v/tinyvec.svg)](https://crates.io/crates/tinyvec)
4 [![docs.rs](https://docs.rs/tinyvec/badge.svg)](https://docs.rs/tinyvec/)
5
6 ![Unsafe-Zero-Percent](https://img.shields.io/badge/Unsafety-0%25-brightgreen.svg)
7
8 # tinyvec
9
10 A 100% safe crate of vec-like types.
11 Not just safe at the public API boundary, fully safe for all internal code too: `#![forbid(unsafe_code)]`
12
13 The provided types are as follows:
14 * `ArrayVec` is an array-backed vec-like data structure. It panics on overflow.
15 * `SliceVec` is similar, but using a `&mut [T]` as the data backing.
16 * `TinyVec` (`alloc` feature) is an enum that's either an `Inline(ArrayVec)` or a `Heap(Vec)`.
17 If a `TinyVec` is `Inline` and would overflow its array it automatically transitions to `Heap` and continues whatever it was doing.
18
19 To attain this "100% safe code" status there is one compromise: the element type of the vecs must implement `Default`.
20
21 For more API details, please see [the docs.rs documentation](https://docs.rs/tinyvec/)
22
23 ## `tinyvec` Alternatives?
24
25 Maybe you don't want to use `tinyvec`, there's other crates you might use instead!
26
27 * [arrayvec](https://docs.rs/arrayvec) is a crate with array-backed structures.
28 * [smallvec](https://docs.rs/smallvec) is a crate where the array-backed data can be moved to the heap on overflow.
29
30 The main difference is that both of those crates use `unsafe` code.
31 This mostly allows them to get rid of the `Default` limitation for elements that `tinyvec` imposes.
32 The `smallvec` and `arrayvec` crates are generally correct, but there's been occasional bugs leading to UB.
33 With `tinyvec`, any uncaught bugs *can't* lead to UB, because the crate is safe code all the way through.
34 If you want that absolute level of assurance against UB, use `tinyvec`.