1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//! Yet another **string type** for Rust 🦀
//!
//! * no copy and `const` **literal wrapping**
//! * no alloc **small strings** (_23 bytes_ on 64-bit platform)
//! * no copy **owned slices**
//! * a niche: `Option<HipStr>` and `HipStr` have the same size
//! * **zero dependency**, except for optional `serde` support
//!
//! Also byte strings, OS strings, paths, too!
//!
//! # Examples
//!
//! ```rust
//! use hipstr::HipStr;
//!
//! let simple_greetings = HipStr::borrowed("Hello world");
//! let clone = simple_greetings.clone(); // no copy
//! std::thread::spawn(move || { println!("{}", clone); });
//!
//! let user = "John";
//! let greetings = HipStr::from(format!("Hello {}", user));
//! let user = greetings.slice(6..); // no copy
//! drop(greetings); // the slice is _owned_, it exists even if greetings disappear
//!
//! let chars = user.chars().count(); // "inherits" `&str` methods
//! ```
//!
//! # Three Representations
//!
//! Each type has three distinct representations:
//!
//! - Borrowed slice
//! - Inline sequence (up to [`HipByt::inline_capacity()`])
//! - Shared reference (cheaply clonable) _and slice_ (sliceable)
//!
//! The shared reference can be thread-safe or not, depending on the backend.
//!
//! Most operations keep string **normalized**, that is, if the string is not
//! borrowed, the inline representation is preferred when possible.
//!
//! ## ⚠️ Warning!
//!
//! The used representation of the empty string is **unspecified** and may
//! change between patch versions! It may be _borrowed_ or _inlined_ but will
//! never be allocated.
//!
//! # Three Backends
//!
//! The crate provides three backends:
//!
//! - `Arc` (atomic reference counting), formerly `ThreadSafe`
//! - `Rc` (reference counting), formerly `Local`
//! - `Unique` (unique reference)
//!
//! The last backend, `Unique`, is mostly an experiment in pushing what
//! constitutes a hipstr backend and has **no practical use**.
//!
//! The crate root also provides some convenience type aliases, typically for
//! strings:
//!
//! - `hipstr::HipStr` with the `Arc` backend,
//! - `hipstr::LocalHipStr` with the `Rc` backend.
//!
//! # Platform Support
//!
//! This crate is only supported on platforms where:
//!
//! - pointers have the same memory size as `usize`,
//! - pointer alignment requirement is strictly greater than **2**.
//!
//! For now, most common architectures are like that. However, `hipstr` will not
//! work on new and future architectures relying on large tagged pointers (e.g.
//! CHERI 128-bit pointers).
//!
//! # Features
//!
//! * `std` (default): uses `std` rather than `core` and `alloc`, and also
//! provides more trait implementations (for comparison, conversions)
//! * `serde`: provides serialization/deserialization support with [`serde`](https://serde.rs)
//! * `borsh`: provides serialization/deserialization support with [`borsh`](https://borsh.io)
//! * `bstr`: provides compatibility with [BurntSushi's bstr
//! crate](https://github.com/BurntSushi/bstr) make `HipByt` deref to
//! [`&bstr::BStr`](bstr::BStr) rather than [`&[u8]`](slice)
//! * `unstable`: do nothing, used to reveal unstable implementation details
extern crate alloc;
extern crate std;
pub
pub
pub
pub use *;
/// Thread-safe shared byte sequence.
pub type HipByt<'borrow> = HipByt;
/// Thread-safe shared string.
pub type HipStr<'borrow> = HipStr;
/// Thread-safe shared string.
pub type HipOsStr<'borrow> = HipOsStr;
/// Thread-safe shared path.
pub type HipPath<'borrow> = HipPath;
/// Thread-local shared byte sequence.
pub type LocalHipByt<'borrow> = HipByt;
/// Thread-local shared string.
pub type LocalHipStr<'borrow> = HipStr;
/// Thread-local shared byte sequence.
pub type LocalHipOsStr<'borrow> = HipOsStr;
/// Thread-local shared path.
pub type LocalHipPath<'borrow> = HipPath;