tinyvec_string/
lib.rs

1//! [`tinyvec`] based string types.
2//!
3//! `tinyvec_string` provides two string types:
4//! * [`ArrayString`], a string backed by a fixed-size array on the stack,
5//!   using [`ArrayVec`]
6//! * [`TinyString`], a string backed by either a fixed-size array on the stack
7//!   or a [`Vec`] on the heap
8//!
9//! ## Features
10//!
11//! Like `tinyvec`, `tinyvec_string` is `no_std` by default.
12//!
13//! `ArrayString` has no dependencies (other than `tinyvec` and `core`).
14//!
15//! `TinyString` requires the the `alloc` cargo feature to be enabled because
16//! it has a dependency on `alloc`:
17//!
18//! ```toml
19//! [dependencies]
20//! tinyvec_string = { version = "0.3.2", features = ["alloc"] }
21//! ```
22//!
23//! Error types implement `std::error::Error` when the `std` feature is
24//! enabled.
25//!
26//! The `rustc_1_40` feature enables `tinyvec`'s `rustc_1_40` feature, which enables
27//! some optimizations for Rust versions >= 1.40.
28//!
29//! The `rustc_1_55` feature enables usage of const generics to allow usage of
30//! backing arrays of any size.
31//!
32//! The `rustc_1_57` feature enables `TinyString::try_reserve` and
33//! `TinyString::try_reserve_exact`.
34//!
35//! ## Safety
36//!
37//! This crate strives to be as safe as possible. Almost all internal `unsafe`
38//! code is copied verbatim from `std`'s `String` implementation for maximum
39//! reliability and performance.
40//!
41//! ## MSRV
42//!
43//! Like `tinyvec`, `tinyvec_string` (without `rustc` version features) supports
44//! Rust 1.34+. The `alloc` feature requires Rust 1.36+.
45//!
46//! [`tinyvec`]: tinyvec/index.html
47//! [`ArrayString`]: arraystring/struct.ArrayString.html
48//! [`TinyString`]: tinystring/enum.TinyString.html
49//! [`ArrayVec`]: tinyvec/struct.ArrayVec.html
50//! [`TinyVec`]: tinyvec/enum.TinyVec.html
51//! [`Array`]: tinyvec/trait.Array.html
52//! [`Vec`]: https://doc.rust-lang.org/std/vec/struct.Vec.html
53//! [`std::error::Error`]: https://doc.rust-lang.org/std/error/trait.Error.html
54
55#![cfg_attr(not(feature = "std"), no_std)]
56#![cfg_attr(docs_rs, feature(doc_cfg))]
57// clippy recommends against tabs because of the style guide, which recommends
58// spaces in general, but spaces aren't used for source either.
59// `std::string::String` implements `PartialEq::ne` explicitly, so
60// `tinyvec_string` does as well.
61// `copied`/`cloned` can't be used to support Rust 1.34.
62#![allow(
63	clippy::tabs_in_doc_comments,
64	clippy::partialeq_ne_impl,
65	clippy::map_clone
66)]
67
68#[cfg(feature = "alloc")]
69extern crate alloc;
70
71pub mod arraystring;
72
73pub use arraystring::ArrayString;
74
75#[cfg_attr(docs_rs, doc(cfg(target_feature = "alloc")))]
76#[cfg(feature = "alloc")]
77pub mod tinystring;
78
79#[cfg_attr(docs_rs, doc(cfg(target_feature = "alloc")))]
80#[cfg(feature = "alloc")]
81pub use tinystring::TinyString;
82
83pub mod tinyvec;
84
85pub mod bytearray;