Debian Codegraph @

src/string/mod.rs

raw symbols SCIP
1 //! [String]-like wrappers around [Bytes] and [BytesMut].
2 //!
3 //! The [Bytes] and [BytesMut] provide a buffer of bytes with ability to create owned slices into
4 //! the same shared memory allocation. This allows cheap manipulation of data.
5 //!
6 //! Strings are mostly just byte buffers with extra APIs to manipulate them. The standard [String]
7 //! type is built as a wrapper around [Vec]. We build similar wrappers around the [Bytes] and
8 //! [BytesMut], gaining the ability to create owned shared slices for textual data as well.
9 //!
10 //! Users are expected to use the [Str] and [StrMut] types. Note that these are type aliases around
11 //! the [StrInner] type. The latter is means to implement both in one go and contains all the
12 //! documentation, but is not meant to be used directly.
13 //!
14 //! # Splitting
15 //!
16 //! The [prim@str] type from standard library (which the types here dereference to) allows for
17 //! slicing and splitting in many convenient ways. They, however, return borrowed string slices
18 //! (`&str`), which might pose some problems.
19 //!
20 //! The [Str], and to certain extent, the [StrMut] type additionally allow cheap splitting and
21 //! slicing that produce owned [Str] and [StrMut] respectively. They are slightly more expensive
22 //! than the slicing than the ones returning `&str`, but only by incrementing internal reference
23 //! counts. They do not clone the actual string data, like `.to_owned()` on the standard library
24 //! methods would. These methods are available in addition to the standard ones.
25 //!
26 //! There are three ways how this can be done:
27 //!
28 //! * By dedicated methods, like [lines_bytes][StrInner::lines_bytes] (in general, the name of the
29 //! standard method suffixed with `_bytes`).
30 //! * By using the [BytesIter] iterator manually.
31 //! * By using the standard-library methods, producing `&str` and translating it back to [Str] with
32 //! [slice][StrInner::slice] or [StrInner::slice_ref].
33 //!
34 //! # Examples
35 //!
36 //! ```rust
37 //! # use bytes::Bytes;
38 //! # use bytes_utils::{Str, StrMut};
39 //! let mut builder = StrMut::new();
40 //! builder += "Hello";
41 //! builder.push(' ');
42 //! builder.push_str("World");
43 //! assert_eq!("Hello World", builder);
44 //!
45 //! let s1 = builder.split_built().freeze();
46 //! // This is a cheap copy, in the form of incrementing a reference count.
47 //! let s2 = s1.clone();
48 //! assert_eq!("Hello World", s1);
49 //! assert_eq!("Hello World", s2);
50 //! // Slicing is cheap as well, even though the returned things are Str and therefore owned too.
51 //! assert_eq!("ello", s1.slice(1..5));
52 //! // We have taken the data out of the builder, but the rest of its capacity can be used for
53 //! // further things.
54 //! assert_eq!("", builder);
55 //!
56 //! // Creating from strings and similar works
57 //! let a = Str::from("Hello");
58 //! assert_eq!("Hello", a);
59 //!
60 //! let e = Str::new();
61 //! assert_eq!("", e);
62 //!
63 //! // And from static str in O(1)
64 //! let b = Str::from_static("World");
65 //! assert_eq!("World", b);
66 //!
67 //! // And from Bytes too.
68 //! let b = Str::try_from(Bytes::from_static(b"World")).expect("Must be utf8");
69 //! assert_eq!("World", b);
70 //! // Invalid utf8 is refused.
71 //! Str::try_from(Bytes::from_static(&[0, 0, 255])).unwrap_err();
72 //! ```
73
74 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#;
75 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::boxedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/::Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#;
76 use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/::Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#;
77 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/::{Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#, BorrowMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/BorrowMut#};
78 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#;
79 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::convertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/::Infalliblerust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Infallible#;
80 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/::{Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#, Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#, Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#, Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# as FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result#, Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write#};
81 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/::{Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash#, Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#};
82 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/, FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#};
83 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::{Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#, AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#, Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref#, DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut#, Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#, IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#};
84 use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::{selfrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/, FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#};
85
86 #[cfg(feature = "std")]
87 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#;
88
89 use bytesrust-analyzer cargo bytes 1.12.1 crate/::{Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#, BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#};
90 use eitherrust-analyzer cargo either 1.18.0 crate/::Eitherrust-analyzer cargo either 1.18.0 Either#;
91
92 #[cfg(feature = "serde")]
93 mod serde_implrust-analyzer cargo bytes-utils 0.1.4 string/serde_impl/;
94
95 /// Error when creating [Str] or [StrMut] from invalid UTF8 data.
96 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
97 pub struct Utf8Errorrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#<S> {
98 erust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#e.: corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::Utf8Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/error/Utf8Error#,
99 innerrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#inner.: S,
100 }
101
102 impl<S> Utf8Errorrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#<S> {
103 /// Returns the byte buffer back to the caller.
104 pub fn into_innerrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`Utf8Error<S>`]into_inner().(self) -> S {
105 self.innerrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#inner.
106 }
107
108 /// The inner description of why the data is invalid UTF8.
109 pub fn utf8_errorrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`Utf8Error<S>`]utf8_error().(&self) -> strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::Utf8Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/error/Utf8Error# {
110 self.erust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#e.
111 }
112 }
113
114 impl<S> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for Utf8Errorrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#<S> {
115 fn fmtrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`Utf8Error<S>`][Display]fmt().(&self, fmt: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
116 Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/error/impl#[Utf8Error][Display]fmt().(&self.erust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#e., fmt)
117 }
118 }
119
120 #[cfg(feature = "std")]
121 impl<S: Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#> Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for Utf8Errorrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#<S> {}
122
123 /// Direction of iteration.
124 ///
125 /// See [BytesIter].
126 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:)]
127 pub enum Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction# {
128 /// Move forward (in the normal direction) in the string.
129 Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#,
130
131 /// Move backwards in the string.
132 Backwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Backward#,
133 }
134
135 /// Manual splitting iterator.
136 ///
137 /// The methods on [Str] and [StrMut] that iterate use this internally. But it can also be used
138 /// manually to generate other iterators that split the original into parts.
139 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)]
140 pub struct BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#<S, F> {
141 bytesrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#bytes.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<S>,
142 extractrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#extract.: F,
143 directionrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#direction.: Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#,
144 }
145
146 impl<S, F> BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#<S, F>
147 where
148 S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#,
149 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)>,
150 {
151 /// A constructor of the iterator.
152 ///
153 /// The `direction` specifies in what order chunks should be yielded.
154 ///
155 /// The `ext` closure is always called with the rest of not yet split string. It shall return
156 /// the byte indices of the chunk and separator border. In case of forward iteration, it is the
157 /// end of them and the separator needs to end further to the string (or at the same position).
158 /// In the backwards direction, it is in reverse ‒ they specify their starts and the separator
159 /// is before the chunk.
160 ///
161 /// # Panics
162 ///
163 /// If the indices don't point at a character boundary, the iteration will panic. It'll also
164 /// panic if the returned indices are reversed or if they are out of bounds.
165 pub fn newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(s: StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>, direction: Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#, ext: F) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`] {
166 Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`] {
167 bytesrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#bytes.: Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(s.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0.),
168 extractrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#extract.: ext,
169 directionrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#direction.,
170 }
171 }
172 }
173
174 impl<S, F> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#<S, F>
175 where
176 S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#,
177 F: FnMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnMut#(&str) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)>,
178 {
179 type Itemrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`][Iterator]Item# = StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>;
180
181 fn nextrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>> {
182 let storage = self.bytesrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#bytes..takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]take().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
183 // Safety: we keep sure it is valid UTF8 on the API boundary.
184 let whole_str = unsafe { strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked().(storage.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) };
185 fn splitrust-analyzer cargo bytes-utils 0.1.4 string/split().<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#>(storage: S, left: usize, right: usize) -> (S, S) {
186 let whole_str = unsafe { strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked().(storage.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) };
187 // Sanity-check we are not slicing in the middle of utf8 code point. This would
188 // panic if we do. It would also panic if we are out of range, which is also good.
189 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(whole_str.is_char_boundaryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_char_boundary().(left));
190 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(whole_str.is_char_boundaryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_char_boundary().(right));
191
192 // Now that we are sure this is legal, we are going to slice the byte data for real.
193 let (with_sep, end) = storage.split_atrust-analyzer cargo bytes-utils 0.1.4 string/Storage#split_at().(right);
194 let (start, _sep) = with_sep.split_atrust-analyzer cargo bytes-utils 0.1.4 string/Storage#split_at().(left);
195 (start, end)
196 }
197 match ((self.extractrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#extract.)(whole_str), self.directionrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#direction.) {
198 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((chunk_end, sep_end)), Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#) => {
199 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(chunk_end <= sep_end);
200 let (start, end) = splitrust-analyzer cargo bytes-utils 0.1.4 string/split().(storage, chunk_end, sep_end);
201
202 self.bytesrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#bytes. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(end);
203 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#(start))
204 }
205 (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((chunk_start, sep_start)), Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Backwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Backward#) => {
206 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(sep_start <= chunk_start);
207 let (start, end) = splitrust-analyzer cargo bytes-utils 0.1.4 string/split().(storage, sep_start, chunk_start);
208
209 self.bytesrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#bytes. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start);
210 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#(end))
211 }
212 (Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#, _) => {
213 // No separator found -> return the whole rest (and keep None in ourselves)
214 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#(storage))
215 }
216 }
217 }
218 }
219
220 /// Find a separator position, for use with the [BytesIter].
221 fn sep_findrust-analyzer cargo bytes-utils 0.1.4 string/sep_find().<F: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(char) -> bool>(s: &str, is_sep: F) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)> {
222 let sep_start = s.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(&is_sep)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
223 let sep_end = s[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().sep_start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().
224 .findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(|c| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_sep(c))
225 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|e| e rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().sep_start)
226 .unwrap_or_elserust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or_else().(|| s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
227 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((sep_start, sep_end))
228 }
229
230 /// Separator for an empty pattern.
231 fn empty_seprust-analyzer cargo bytes-utils 0.1.4 string/empty_sep().(s: &str, limit: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)> {
232 let char_end = s
233 .char_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]char_indices().()
234 .skiprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#skip().(1)
235 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, _)| i)
236 .chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(s.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().((!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().()) as usize))
237 .takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(limit)
238 .nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/impl#[`Take<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
239 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((char_end, char_end))
240 }
241
242 fn rempty_seprust-analyzer cargo bytes-utils 0.1.4 string/rempty_sep().(s: &str, limit: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<(usize, usize)> {
243 let char_start = s.char_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]char_indices().().revrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#rev().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|(i, _)| i).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(limit).nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/take/impl#[`Take<I>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch().;
244 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#((char_start, char_start))
245 }
246
247 /// The backing storage for [StrInner]
248 ///
249 /// This is currently a technical detail of the crate, users are not expected to implement this
250 /// trait. Use [Str] or [StrMut] type aliases.
251 ///
252 /// # Safety
253 ///
254 /// The storage must act "sane". But what exactly it means is not yet analyzed and may change in
255 /// future versions. Don't implement the trait (at least not yet).
256 pub unsafe trait Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> + Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# {
257 /// A type that can be used to build the storage incrementally.
258 ///
259 /// For mutable storages, it may be itself. For immutable one, there needs to be a mutable
260 /// counterpart that can be converted to immutable later on.
261 type Creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#Creator#: Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# + StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#;
262
263 /// Converts the creator (mutable storage) to self.
264 ///
265 /// In case of mutable storages, this should be identity.
266 fn from_creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#from_creator().(creator: Self::Creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#Creator#) -> Self;
267
268 /// Splits the storage at the given byte index and creates two non-overlapping instances.
269 fn split_atrust-analyzer cargo bytes-utils 0.1.4 string/Storage#split_at().(self, at: usize) -> (Self, Self);
270 }
271
272 unsafe impl Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage# for Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes# {
273 type Creatorrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage]Creator# = BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#;
274 fn from_creatorrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage]from_creator().(creator: Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage]::Creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#Creator#) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage] {
275 creator.freezerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]freeze().()
276 }
277 fn split_atrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage]split_at().(mut self, at: usize) -> (Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage], Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[Bytes][Storage]) {
278 let right = self.split_offrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]split_off().(at);
279 (self, right)
280 }
281 }
282
283 unsafe impl Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage# for BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut# {
284 type Creatorrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage]Creator# = BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#;
285 fn from_creatorrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage]from_creator().(creator: Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage]::Creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#Creator#) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage] {
286 creator
287 }
288 fn split_atrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage]split_at().(mut self, at: usize) -> (Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage], Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][Storage]) {
289 let right = self.split_offrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split_off().(at);
290 (self, right)
291 }
292 }
293
294 /// Trait for extra functionality of a mutable storage.
295 ///
296 /// This is in addition to what an immutable storage must satisfy.
297 ///
298 /// # Safety
299 ///
300 /// The storage must act "sane". But what exactly it means is not yet analyzed and may change in
301 /// future versions. Don't implement the trait (at least not yet).
302 pub unsafe trait StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage# + AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<[u8]> {
303 /// An immutable counter-part storage.
304 type Immutablerust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#Immutable#: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#<Creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#Creator# = Self>;
305
306 /// Adds some more bytes to the end of the storage.
307 fn push_slicerust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#push_slice().(&mut self, s: &[u8]);
308 }
309
310 unsafe impl StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut# for BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut# {
311 type Immutablerust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][StorageMut]Immutable# = Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#;
312 fn push_slicerust-analyzer cargo bytes-utils 0.1.4 string/impl#[BytesMut][StorageMut]push_slice().(&mut self, s: &[u8]) {
313 self.extend_from_slicerust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]extend_from_slice().(s)
314 }
315 }
316
317 /// Implementation of the [Str] and [StrMut] types.
318 ///
319 /// For technical reasons, both are implemented in one go as this type. For the same reason, most
320 /// of the documentation can be found here. Users are expected to use the [Str] and [StrMut]
321 /// instead.
322 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default:)]
323 pub struct StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>(S);
324
325 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
326 /// Creates an empty instance.
327 pub fn newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]new().() -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`] {
328 Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]::defaultrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Default]default().()
329 }
330
331 /// Extracts the inner byte storage.
332 pub fn into_innerrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]into_inner().(self) -> S {
333 self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0.
334 }
335
336 /// Access to the inner storage.
337 pub fn innerrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]inner().(&self) -> &S {
338 &self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0.
339 }
340
341 /// Creates an instance from an existing byte storage.
342 ///
343 /// It may fail if the content is not valid UTF8.
344 ///
345 /// A [try_from][TryFrom::try_from] may be used instead.
346 pub fn from_innerrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]from_inner().(s: S) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`], Utf8Errorrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#<S>> {
347 match strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(s.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) {
348 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(_) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`](s)),
349 Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(e) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Utf8Errorrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error# { erust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#e., innerrust-analyzer cargo bytes-utils 0.1.4 string/Utf8Error#inner.: s }),
350 }
351 }
352
353 /// Same as [from_inner][StrInner::from_inner], but without the checks.
354 ///
355 /// # Safety
356 ///
357 /// The caller must ensure content is valid UTF8.
358 pub const unsafe fn from_inner_uncheckedrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]from_inner_unchecked().(s: S) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`] {
359 Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`](s)
360 }
361
362 /// Splits the string into two at the given index.
363 ///
364 /// # Panics
365 ///
366 /// If the index is not at char boundary.
367 pub fn split_at_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_at_bytes().(self, at: usize) -> (Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`], Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]) {
368 assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().().is_char_boundaryrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_char_boundary().(at));
369 let (l, r) = self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0..split_atrust-analyzer cargo bytes-utils 0.1.4 string/Storage#split_at().(at);
370 (Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`](l), Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`](r))
371 }
372
373 /// Splits into whitespace separated "words".
374 ///
375 /// This acts like [split_whitespace][str::split_whitespace], but yields owned instances. It
376 /// doesn't clone the content, it just increments some reference counts.
377 pub fn split_whitespace_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_whitespace_bytes().(self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> {
378 BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, |s| {
379 sep_findrust-analyzer cargo bytes-utils 0.1.4 string/sep_find().(s, char::is_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_whitespace().)
380 })
381 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|s| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().())
382 }
383
384 /// Splits into whitespace separated "words".
385 ///
386 /// This acts like [split_ascii_whitespace][str::split_ascii_whitespace], but yields owned
387 /// instances. This doesn't clone the content, it just increments some reference counts.
388 pub fn split_ascii_whitespace_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_ascii_whitespace_bytes().(self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> {
389 BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, |s| {
390 sep_findrust-analyzer cargo bytes-utils 0.1.4 string/sep_find().(s, |c| c.is_asciirust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_ascii().() && (c as u8).is_ascii_whitespacerust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u8]is_ascii_whitespace().())
391 })
392 .filterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#filter().(|s| !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().s.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().())
393 }
394
395 /// Splits into lines.
396 ///
397 /// This acts like [lines][str::lines], but yields owned instances. The content is not cloned,
398 /// this just increments some reference counts.
399 pub fn lines_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]lines_bytes().(self) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> {
400 if self.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
401 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/empty/empty().())
402 } else {
403 let iter = BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, |s| sep_findrust-analyzer cargo bytes-utils 0.1.4 string/sep_find().(s, |c| c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'\n'))
404 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|s| match s.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().().nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`Chars<'a>`][Iterator]next().() {
405 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#('\r') => s.split_at_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_at_bytes().(1).1,
406 _ => s,
407 });
408 Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(iter)
409 }
410 }
411
412 /// Splits with the provided separator.
413 ///
414 /// This acts somewhat like [split][str::split], but yields owned instances. Also, it accepts
415 /// only string patters (since the `Pattern` is not stable ☹). The content is not cloned, this
416 /// just increments some reference counts.
417 pub fn split_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_bytes().<'s>(self, sep: &'s str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> + 's
418 where
419 S: 's,
420 {
421 if sep.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
422 let bulk = BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, |s| empty_seprust-analyzer cargo bytes-utils 0.1.4 string/empty_sep().(s, usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.));
423 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]::defaultrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Default]default().()).chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(bulk))
424 } else {
425 let sep_find = move |s: &str| s.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(sep).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|pos| (pos, pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().sep.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()));
426 Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, sep_find))
427 }
428 }
429
430 /// Splits max. `n` times according to the given pattern.
431 ///
432 /// This acts somewhat like [splitn][str::splitn], but yields owned instances. Also, it accepts
433 /// only string patters (since the `Pattern` is not stable ☹). The content is not cloned, this
434 /// just increments some reference counts.
435 pub fn splitn_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]splitn_bytes().<'s>(self, mut n: usize, sep: &'s str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> + 's
436 where
437 S: 's,
438 {
439 // TODO: This seems to work, but is ugly. Any idea how to simplify?
440 if sep.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
441 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().1 {
442 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(self).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(n)))
443 } else {
444 n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
445 let bulk = BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, move |s| {
446 n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
447 empty_seprust-analyzer cargo bytes-utils 0.1.4 string/empty_sep().(s, n)
448 });
449 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]::defaultrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Default]default().()).chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(bulk)))
450 }
451 } else {
452 let sep_find = move |s: &str| {
453 n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
454 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
455 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
456 } else {
457 s.findrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]find().(sep).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|pos| (pos, pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().sep.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()))
458 }
459 };
460 Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Forwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Forward#, sep_find).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(n))
461 }
462 }
463
464 /// A reverse version of [split_bytes][Self::split_bytes].
465 pub fn rsplit_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]rsplit_bytes().<'s>(self, sep: &'s str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> + 's
466 where
467 S: 's,
468 {
469 if sep.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
470 let bulk = BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Backwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Backward#, |s| rempty_seprust-analyzer cargo bytes-utils 0.1.4 string/rempty_sep().(s, usize::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[usize]MAX.));
471 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]::defaultrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Default]default().()).chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(bulk))
472 } else {
473 let sep_find = move |s: &str| s.rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rfind().(sep).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|pos| (pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().sep.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(), pos));
474 Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Backwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Backward#, sep_find))
475 }
476 }
477
478 /// A reverse version of [splitn_bytes][Self::splitn_bytes].
479 pub fn rsplitn_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]rsplitn_bytes().<'s>(self, mut n: usize, sep: &'s str) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]> + 's
480 where
481 S: 's,
482 {
483 // TODO: This seems to work, but is ugly. Any idea how to simplify?
484 if sep.is_emptyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]is_empty().() {
485 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().<=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]le().1 {
486 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(self).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(n)))
487 } else {
488 n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
489 let bulk = BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Backwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Backward#, move |s| {
490 n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
491 rempty_seprust-analyzer cargo bytes-utils 0.1.4 string/rempty_sep().(s, n)
492 });
493 Eitherrust-analyzer cargo either 1.18.0 Either#::Leftrust-analyzer cargo either 1.18.0 Either#Left#(Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::oncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/once/once().(Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]::defaultrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Default]default().()).chainrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#chain().(bulk)))
494 }
495 } else {
496 let sep_find = move |s: &str| {
497 n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().-=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`SubAssign<Self>`]sub_assign().1;
498 if n rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 {
499 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
500 } else {
501 s.rfindrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]rfind().(sep).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map().(|pos| (pos rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().sep.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(), pos))
502 }
503 };
504 Eitherrust-analyzer cargo either 1.18.0 Either#::Rightrust-analyzer cargo either 1.18.0 Either#Right#(BytesIterrust-analyzer cargo bytes-utils 0.1.4 string/BytesIter#::newrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`BytesIter<S, F>`]new().(self, Directionrust-analyzer cargo bytes-utils 0.1.4 string/Direction#::Backwardrust-analyzer cargo bytes-utils 0.1.4 string/Direction#Backward#, sep_find).takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(n))
505 }
506 }
507 }
508
509 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
510 /// Appends a string.
511 pub fn push_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push_str().(&mut self, s: &str) {
512 self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0..push_slicerust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#push_slice().(s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
513 }
514
515 /// Appends one character.
516 pub fn pushrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push().(&mut self, c: char) {
517 self.push_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push_str().(c.encode_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]encode_utf8().(&mut [0; 4]));
518 }
519
520 /// Provides mutable access to the inner buffer.
521 ///
522 /// # Safety
523 ///
524 /// The caller must ensure that the content stays valid UTF8.
525 pub unsafe fn inner_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]inner_mut().(&mut self) -> &mut S {
526 &mut self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0.
527 }
528
529 /// Turns the mutable variant into an immutable one.
530 ///
531 /// The advantage is that it can then be shared (also by small parts).
532 pub fn freezerust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]freeze().(self) -> StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S::Immutablerust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#Immutable#> {
533 StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#(S::Immutablerust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#Immutable#::from_creatorrust-analyzer cargo bytes-utils 0.1.4 string/Storage#from_creator().(self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0.))
534 }
535 }
536
537 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
538 type Targetrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]Target# = str;
539
540 fn derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().(&self) -> &str {
541 unsafe { strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8_uncheckedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked().(self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()) }
542 }
543 }
544
545 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
546 fn deref_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][DerefMut]deref_mut().(&mut self) -> &mut str {
547 unsafe { strrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/::from_utf8_unchecked_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8_unchecked_mut().(self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0..as_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#as_mut().()) }
548 }
549 }
550
551 impl<S, T> AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<T> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>
552 where
553 S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#,
554 str: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<T>,
555 {
556 fn as_refrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`AsRef<T>`]as_ref().(&self) -> &T {
557 self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().().as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()
558 }
559 }
560
561 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<str> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
562 fn as_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`AsMut<str>`]as_mut().(&mut self) -> &mut str {
563 self.deref_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][DerefMut]deref_mut().()
564 }
565 }
566
567 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<str> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
568 fn borrowrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Borrow<str>`]borrow().(&self) -> &str {
569 self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().()
570 }
571 }
572
573 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> BorrowMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/BorrowMut#<str> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
574 fn borrow_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`BorrowMut<str>`]borrow_mut().(&mut self) -> &mut str {
575 self.deref_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][DerefMut]deref_mut().()
576 }
577 }
578
579 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
580 fn fmtrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Debug]fmt().(&self, fmt: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
581 Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[str][Debug]fmt().(self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().(), fmt)
582 }
583 }
584
585 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
586 fn fmtrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Display]fmt().(&self, fmt: &mut Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
587 Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/impl#[str][Display]fmt().(self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().(), fmt)
588 }
589 }
590
591 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hash# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
592 fn hashrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Hash]hash().<H: Hasherrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/Hasher#>(&self, state: &mut H) {
593 self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().().hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/impls/impl#[str][Hash]hash().(state)
594 }
595 }
596
597 impl<S, I> Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<I> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>
598 where
599 S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#,
600 str: Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<I>,
601 {
602 type Outputrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Index<I>`]Output# = <str as Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<I>>::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output#;
603
604 fn indexrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Index<I>`]index().(&self, index: I) -> &Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Index<I>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# {
605 self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().().indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().(index)
606 }
607 }
608
609 impl<S, I> IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<I> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S>
610 where
611 S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#,
612 str: IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<I>,
613 {
614 fn index_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`IndexMut<I>`]index_mut().(&mut self, index: I) -> &mut Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`IndexMut<I>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# {
615 self.deref_mutrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][DerefMut]deref_mut().().index_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().(index)
616 }
617 }
618
619 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#<&str> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
620 type Outputrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Add<&str>`]Output# = Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Add<&str>`];
621
622 fn addrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Add<&str>`]add().(mut self, rhs: &str) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Add<&str>`]::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#Output# {
623 self.push_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push_str().(rhs);
624 self
625 }
626 }
627
628 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#<&str> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
629 fn add_assignrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`AddAssign<&str>`]add_assign().(&mut self, rhs: &str) {
630 self.push_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push_str().(rhs);
631 }
632 }
633
634 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<char> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
635 fn extendrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Extend<char>`]extend().<T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = char>>(&mut self, iter: T) {
636 for c in iter {
637 self.pushrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push().(c);
638 }
639 }
640 }
641
642 impl<'a, S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<&'a char> for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
643 fn extendrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`Extend<&'a char>`]extend().<T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = &'a char>>(&mut self, iter: T) {
644 for c in iter {
645 self.pushrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().c);
646 }
647 }
648 }
649
650 macro_rules! impl_extendrust-analyzer cargo bytes-utils 0.1.4 string/impl_extend! {
651 ($ty:ty $(, $lifetimes:lifetime )* ) => {
652 impl<$($lifetimes, )* S: StorageMut> Extend<$ty> for StrInner<S> {
653 fn extend<T: IntoIterator<Item = $ty>>(&mut self, iter: T) {
654 for i in iter {
655 self.push_str(i.as_ref());
656 }
657 }
658 }
659
660 impl<$($lifetimes, )* S> FromIterator<$ty> for StrInner<S>
661 where
662 S: Storage,
663 {
664 fn from_iter<T: IntoIterator<Item = $ty>>(iter: T) -> Self {
665 let mut creator = StrInner(S::Creator::default());
666 creator.extend(iter);
667 StrInner(S::from_creator(creator.0))
668 }
669 }
670 };
671 }
672
673 impl_extendrust-analyzer cargo bytes-utils 0.1.4 string/impl_extend!!(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#);
674 impl_extendrust-analyzer cargo bytes-utils 0.1.4 string/impl_extend!!(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>);
675 impl_extendrust-analyzer cargo bytes-utils 0.1.4 string/impl_extend!!(&'a Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, 'a);
676 impl_extendrust-analyzer cargo bytes-utils 0.1.4 string/impl_extend!!(&'a str, 'a);
677 impl_extendrust-analyzer cargo bytes-utils 0.1.4 string/impl_extend!!(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>, 'a);
678
679 macro_rules! impl_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_from! {
680 ($ty:ty $(, $lifetimes:lifetime )* ) => {
681 impl<$($lifetimes, )* S> From<$ty> for StrInner<S>
682 where
683 S: Storage,
684 {
685 fn from(s: $ty) -> Self {
686 iter::once(s).collect()
687 }
688 }
689 };
690 }
691
692 impl_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_from!!(&'a Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, 'a);
693 impl_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_from!!(&'a str, 'a);
694 impl_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_from!!(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>, 'a);
695
696 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> for Strrust-analyzer cargo bytes-utils 0.1.4 string/Str# {
697 fn fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`][`From<String>`]from().(s: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`][`From<String>`] {
698 let inner = Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::fromrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes][`From<Vec<u8>>`]from().(s.into_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]into_bytes().());
699 // Safety: inner is constructed from a str
700 unsafe { Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::from_inner_uncheckedrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]from_inner_unchecked().(inner) }
701 }
702 }
703
704 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>> for Strrust-analyzer cargo bytes-utils 0.1.4 string/Str# {
705 fn fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`][`From<Box<str>>`]from().(s: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`][`From<Box<str>>`] {
706 let s: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<[u8]> = s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().();
707 let inner = Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::fromrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes][`From<Box<[u8]>>`]from().(s);
708 // Safety: inner is constructed from a str
709 unsafe { Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::from_inner_uncheckedrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]from_inner_unchecked().(inner) }
710 }
711 }
712
713 macro_rules! impl_try_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_try_from! {
714 ($ty: ty) => {
715 impl TryFrom<$ty> for StrInner<$ty> {
716 type Error = Utf8Error<$ty>;
717 fn try_from(s: $ty) -> Result<Self, Utf8Error<$ty>> {
718 Self::from_inner(s)
719 }
720 }
721
722 impl From<StrInner<$ty>> for $ty {
723 fn from(s: StrInner<$ty>) -> $ty {
724 s.0
725 }
726 }
727 };
728 }
729
730 impl_try_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_try_from!!(Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#);
731 impl_try_fromrust-analyzer cargo bytes-utils 0.1.4 string/impl_try_from!!(BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#);
732
733 impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<StrMutrust-analyzer cargo bytes-utils 0.1.4 string/StrMut#> for Strrust-analyzer cargo bytes-utils 0.1.4 string/Str# {
734 fn fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`][`From<StrInner<BytesMut>>`]from().(s: StrMutrust-analyzer cargo bytes-utils 0.1.4 string/StrMut#) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`][`From<StrInner<BytesMut>>`] {
735 s.freezerust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]freeze().()
736 }
737 }
738
739 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
740 type Errrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][FromStr]Err# = Infalliblerust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Infallible#;
741
742 fn from_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][FromStr], Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][FromStr]::Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#Err#> {
743 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().())
744 }
745 }
746
747 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
748 fn eqrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`PartialEq<Self>`]eq().(&self, other: &Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`PartialEq<Self>`]) -> bool {
749 self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().other.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().()
750 }
751 }
752
753 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {}
754
755 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
756 fn partial_cmprust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`PartialOrd<Self>`]partial_cmp().(&self, other: &Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`PartialOrd<Self>`]) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering#> {
757 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord#::cmprust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Ord]cmp().(self, other))
758 }
759 }
760
761 impl<S: Storagerust-analyzer cargo bytes-utils 0.1.4 string/Storage#> Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
762 fn cmprust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Ord]cmp().(&self, other: &Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Ord]) -> Orderingrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ordering# {
763 self.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().().cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/impl#[str][Ord]cmp().(other.derefrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Deref]deref().())
764 }
765 }
766
767 macro_rules! impl_partrial_eqrust-analyzer cargo bytes-utils 0.1.4 string/impl_partrial_eq! {
768 ($ty: ty $(, $lifetimes:lifetime )* ) => {
769 impl<$($lifetimes, )* S: Storage> PartialEq<$ty> for StrInner<S> {
770 fn eq(&self, other: &$ty) -> bool {
771 self.deref() == other.deref()
772 }
773 }
774
775 impl<$($lifetimes, )* S: Storage> PartialEq<StrInner<S>> for $ty {
776 fn eq(&self, other: &StrInner<S>) -> bool {
777 self.deref() == other.deref()
778 }
779 }
780
781 impl<$($lifetimes, )* S: Storage> PartialOrd<$ty> for StrInner<S> {
782 fn partial_cmp(&self, other: &$ty) -> Option<Ordering> {
783 Some(self.deref().cmp(other.deref()))
784 }
785 }
786
787 impl<$($lifetimes, )* S: Storage> PartialOrd<StrInner<S>> for $ty {
788 fn partial_cmp(&self, other: &StrInner<S>) -> Option<Ordering> {
789 Some(self.deref().cmp(other.deref()))
790 }
791 }
792 };
793 }
794
795 impl_partrial_eqrust-analyzer cargo bytes-utils 0.1.4 string/impl_partrial_eq!!(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#);
796 impl_partrial_eqrust-analyzer cargo bytes-utils 0.1.4 string/impl_partrial_eq!!(Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<str>);
797 impl_partrial_eqrust-analyzer cargo bytes-utils 0.1.4 string/impl_partrial_eq!!(&'a str, 'a);
798 impl_partrial_eqrust-analyzer cargo bytes-utils 0.1.4 string/impl_partrial_eq!!(&'a mut str, 'a);
799 impl_partrial_eqrust-analyzer cargo bytes-utils 0.1.4 string/impl_partrial_eq!!(Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, str>, 'a);
800
801 impl<S: StorageMutrust-analyzer cargo bytes-utils 0.1.4 string/StorageMut#> Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# for StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<S> {
802 fn write_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][Write]write_str().(&mut self, s: &str) -> FmtResultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# {
803 self.push_strrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]push_str().(s);
804 Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(())
805 }
806 }
807 /// The [format] macro, but returning [Str].
808 ///
809 /// # Examples
810 ///
811 /// ```
812 /// use bytes_utils::{format_bytes, Str};
813 /// let s: Str = format_bytes!("Hello {}", "world");
814 /// assert_eq!("Hello world", s);
815 /// ```
816 #[macro_export]
817 macro_rules! format_bytesrust-analyzer cargo bytes-utils 0.1.4 string/format_bytes! {
818 ($($arg: tt)*) => {
819 $crate::format_bytes_mut!($($arg)*).freeze()
820 }
821 }
822
823 /// The [format] macro, but returning [StrMut].
824 ///
825 /// # Examples
826 ///
827 /// ```
828 /// use bytes_utils::{format_bytes_mut, StrMut};
829 /// let s: StrMut = format_bytes_mut!("Hello {}", "world");
830 /// assert_eq!("Hello world", s);
831 /// ```
832 #[macro_export]
833 macro_rules! format_bytes_mutrust-analyzer cargo bytes-utils 0.1.4 string/format_bytes_mut! {
834 ($($arg: tt)*) => {{
835 use std::fmt::Write;
836 let mut buf = $crate::StrMut::default();
837 write!(buf, $($arg)*).unwrap();
838 buf
839 }}
840 }
841
842 /// An immutable variant of [Bytes]-backed string.
843 ///
844 /// The methods and their documentation are on [StrInner], but users are mostly expected to use
845 /// this and the [StrMut] aliases.
846 pub type Strrust-analyzer cargo bytes-utils 0.1.4 string/Str# = StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#>;
847
848 impl Strrust-analyzer cargo bytes-utils 0.1.4 string/Str# {
849 /// Extracts a subslice of the string as an owned [Str].
850 ///
851 /// # Panics
852 ///
853 /// If the byte indices in the range are not on char boundaries.
854 pub fn slicerust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`]slice().<R>(&self, range: R) -> Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#
855 where
856 str: Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<R, Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# = str>,
857 {
858 self.slice_refrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`]slice_ref().(&self[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().range]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().)
859 }
860
861 /// Extracts owned representation of the slice passed.
862 ///
863 /// This method accepts a string sub-slice of `self`. It then extracts the slice but as the
864 /// [Str] type. This makes it easier to use "ordinary" string parsing/manipulation and then go
865 /// back to holding the [Bytes]-based representation.
866 ///
867 /// This is zero-copy, the common part will be shared by reference counting.
868 ///
869 /// # Panics
870 ///
871 /// If the provided slice is not a sub-slice of `self`. This is checked based on address of the
872 /// slice, not on the content.
873 ///
874 /// # Example
875 ///
876 /// ```rust
877 /// # use bytes_utils::Str;
878 /// let owned = Str::from("Hello World");
879 /// let borrowed_mid: &str = &owned[2..5];
880 ///
881 /// let mid: Str = owned.slice_ref(borrowed_mid);
882 /// assert_eq!("Hello World", owned);
883 /// assert_eq!("llo", mid);
884 /// ```
885 pub fn slice_refrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`]slice_ref().(&self, subslice: &str) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`] {
886 let sub = self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0..slice_refrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]slice_ref().(subslice.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
887 Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`](sub)
888 }
889
890 /// Create [`Str`] from static string in O(1).
891 pub const fn from_staticrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`]from_static().(s: &'static str) -> Selfrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`] {
892 let bytes = Bytesrust-analyzer cargo bytes 1.12.1 bytes/Bytes#::from_staticrust-analyzer cargo bytes 1.12.1 bytes/impl#[Bytes]from_static().(s.as_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]as_bytes().());
893 // Safety: bytes is constructed from str
894 unsafe { Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::from_inner_uncheckedrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]from_inner_unchecked().(bytes) }
895 }
896 }
897
898 /// A mutable variant of [BytesMut]-backed string.
899 ///
900 /// Unlike [Str], this one allows modifications (mostly additions), but also doesn't allow
901 /// overlapping/shared chunks.
902 ///
903 /// This is internally backed by the [StrInner] type, so the documentation of the methods are on
904 /// that.
905 pub type StrMutrust-analyzer cargo bytes-utils 0.1.4 string/StrMut# = StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#<BytesMutrust-analyzer cargo bytes 1.12.1 bytes_mut/BytesMut#>;
906
907 impl StrMutrust-analyzer cargo bytes-utils 0.1.4 string/StrMut# {
908 /// Splits and returns the part of already built string, but keeps the extra capacity.
909 pub fn split_builtrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<BytesMut>`]split_built().(&mut self) -> StrMutrust-analyzer cargo bytes-utils 0.1.4 string/StrMut# {
910 StrInnerrust-analyzer cargo bytes-utils 0.1.4 string/StrInner#(self.0rust-analyzer cargo bytes-utils 0.1.4 string/StrInner#0..splitrust-analyzer cargo bytes 1.12.1 bytes_mut/impl#[BytesMut]split().())
911 }
912 }
913
914 #[cfg(test)]
915 mod testsrust-analyzer cargo bytes-utils 0.1.4 string/tests/ {
916 use itertoolsrust-analyzer cargo itertools 0.12.1 crate/::Itertoolsrust-analyzer cargo itertools 0.12.1 Itertools#;
917 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/;
918
919 use superrust-analyzer cargo bytes-utils 0.1.4 string/::*;
920
921 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
922 fn split_w_byte_indexrust-analyzer cargo bytes-utils 0.1.4 string/tests/split_w_byte_index().() {
923 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("😈 ").split_whitespace_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_whitespace_bytes().().collect_vecrust-analyzer cargo itertools 0.12.1 Itertools#collect_vec().();
924 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(1, v.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
925 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("😈", v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
926 }
927
928 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
929 fn split_samerust-analyzer cargo bytes-utils 0.1.4 string/tests/split_same().() {
930 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("a").split_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_bytes().("a").collect_vecrust-analyzer cargo itertools 0.12.1 Itertools#collect_vec().();
931 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(2, v.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
932 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
933 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
934 }
935
936 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
937 fn split_empty_patrust-analyzer cargo bytes-utils 0.1.4 string/tests/split_empty_pat().() {
938 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("a").split_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_bytes().("").collect_vecrust-analyzer cargo itertools 0.12.1 Itertools#collect_vec().();
939 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(3, v.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
940 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().0]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
941 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("a", v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
942 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", v[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().2]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().);
943 }
944
945 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
946 fn slice_checks_char_boundariesrust-analyzer cargo bytes-utils 0.1.4 string/tests/slice_checks_char_boundaries().() {
947 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("😈");
948 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(4, v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
949 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::catch_unwindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/catch_unwind().(|| v.slicerust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<Bytes>`]slice().(1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#)).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
950 }
951
952 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
953 fn split_at_bytes_midrust-analyzer cargo bytes-utils 0.1.4 string/tests/split_at_bytes_mid().() {
954 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("hello");
955 let (l, r) = v.split_at_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_at_bytes().(2);
956 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("he", l);
957 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("llo", r);
958 }
959
960 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
961 fn split_at_bytes_beginrust-analyzer cargo bytes-utils 0.1.4 string/tests/split_at_bytes_begin().() {
962 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("hello");
963 let (l, r) = v.split_at_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_at_bytes().(0);
964 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", l);
965 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hello", r);
966 }
967
968 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
969 fn split_at_bytes_endrust-analyzer cargo bytes-utils 0.1.4 string/tests/split_at_bytes_end().() {
970 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("hello");
971 let (l, r) = v.split_at_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_at_bytes().(5);
972 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("hello", l);
973 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!("", r);
974 }
975
976 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
977 fn split_at_bytes_panicrust-analyzer cargo bytes-utils 0.1.4 string/tests/split_at_bytes_panic().() {
978 let v = Strrust-analyzer cargo bytes-utils 0.1.4 string/Str#::fromrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`][`From<&'a str>`]from().("😈");
979 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(4, v.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().());
980 panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/::catch_unwindrust-analyzer cargo std https://github.com/rust-lang/rust/library/std panic/catch_unwind().(|| v.split_at_bytesrust-analyzer cargo bytes-utils 0.1.4 string/impl#[`StrInner<S>`]split_at_bytes().(2)).unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().();
981 }
982
983 #[cfg(not(miri))]
984 mod proptests {
985 use proptestrust-analyzer cargo proptest 1.11.0 crate/::preluderust-analyzer cargo proptest 1.11.0 prelude/::*;
986
987 use superrust-analyzer cargo bytes-utils 0.1.4 string/::*;
988
989 proptestrust-analyzer cargo proptest 1.11.0 crate/! {
990 #[test]
991 fn split_whitespace(s: String) {
992 let bstring = Str::from(&s);
993
994 let bw = bstring.split_whitespace_bytes();
995 let sw = s.split_whitespace();
996
997 for (b, s) in bw.zip_eq(sw) {
998 prop_assert_eq!(b, s);
999 }
1000 }
1001
1002 #[test]
1003 fn split_ascii_whitespace(s: String) {
1004 let bstring = Str::from(&s);
1005
1006 let bw = bstring.split_ascii_whitespace_bytes();
1007 let sw = s.split_ascii_whitespace();
1008
1009 for (b, s) in bw.zip_eq(sw) {
1010 prop_assert_eq!(b, s);
1011 }
1012 }
1013
1014 #[test]
1015 fn lines(s: String) {
1016 let bstring = Str::from(&s);
1017
1018 let bl = bstring.lines_bytes();
1019 let sl = s.lines();
1020
1021 for (b, s) in bl.zip_eq(sl) {
1022 prop_assert_eq!(b, s);
1023 }
1024 }
1025
1026 #[test]
1027 fn split(s: String, pat: String) {
1028 let bstring = Str::from(&s);
1029
1030 let bs = bstring.split_bytes(&pat);
1031 let ss = s.split(&pat);
1032
1033 for (b, s) in bs.zip_eq(ss) {
1034 prop_assert_eq!(b, s);
1035 }
1036 }
1037
1038 #[test]
1039 fn split_n(s: String, pat: String, n in 0..5usize) {
1040 let bstring = Str::from(&s);
1041
1042 let bs = bstring.splitn_bytes(n, &pat);
1043 let ss = s.splitn(n, &pat);
1044
1045 for (b, s) in bs.zip_eq(ss) {
1046 prop_assert_eq!(b, s);
1047 }
1048 }
1049
1050 #[test]
1051 fn rsplit(s: String, pat: String) {
1052 let bstring = Str::from(&s);
1053
1054 let bs = bstring.rsplit_bytes(&pat);
1055 let ss = s.rsplit(&pat);
1056
1057 for (b, s) in bs.zip_eq(ss) {
1058 prop_assert_eq!(b, s);
1059 }
1060 }
1061
1062 #[test]
1063 fn rsplit_n(s: String, pat: String, n in 0..5usize) {
1064 let bstring = Str::from(&s);
1065
1066 let bs = bstring.rsplitn_bytes(n, &pat);
1067 let ss = s.rsplitn(n, &pat);
1068
1069 for (b, s) in bs.zip_eq(ss) {
1070 prop_assert_eq!(b, s);
1071 }
1072 }
1073 }
1074 }
1075 }