| 1 |
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/::{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#, Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#, ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#}; |
| 2 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 3 |
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#; |
| 4 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 5 |
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#; |
| 6 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/::Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#; |
| 7 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::syncrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/::Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#; |
| 8 |
#[cfg(feature = "std")] |
| 9 |
use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/::Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#; |
| 10 |
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/::FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#; |
| 11 |
use corerust-analyzer cargo core https://github.com/rust-lang/rust/library/core crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 12 |
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#}; |
| 13 |
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/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 14 |
#[cfg(feature = "std")] |
| 15 |
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#; |
| 16 |
#[cfg(feature = "std")] |
| 17 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::{CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#, CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#}; |
| 18 |
|
| 19 |
use ascii_char::AsciiChar; |
| 20 |
use ascii_str::{AsAsciiStr, AsAsciiStrError, AsciiStr}; |
| 21 |
|
| 22 |
/// A growable string stored as an ASCII encoded buffer. |
| 23 |
#[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:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:, PartialOrdrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialOrd:, Ordrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Ord:, Hashrust-analyzer cargo core https://github.com/rust-lang/rust/library/core hash/macros/Hash:)] |
| 24 |
#[repr(transparent)] |
| 25 |
pub struct AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 26 |
vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#>, |
| 27 |
} |
| 28 |
|
| 29 |
impl AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 30 |
/// Creates a new, empty ASCII string buffer without allocating. |
| 31 |
/// |
| 32 |
/// # Examples |
| 33 |
/// ``` |
| 34 |
/// # use ascii::AsciiString; |
| 35 |
/// let mut s = AsciiString::new(); |
| 36 |
/// ``` |
| 37 |
#[inline] |
| 38 |
#[must_use] |
| 39 |
pub const fn newrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]new().() -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString] { |
| 40 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().() } |
| 41 |
} |
| 42 |
|
| 43 |
/// Creates a new ASCII string buffer with the given capacity. |
| 44 |
/// The string will be able to hold exactly `capacity` bytes without reallocating. |
| 45 |
/// If `capacity` is 0, the ASCII string will not allocate. |
| 46 |
/// |
| 47 |
/// # Examples |
| 48 |
/// ``` |
| 49 |
/// # use ascii::AsciiString; |
| 50 |
/// let mut s = AsciiString::with_capacity(10); |
| 51 |
/// ``` |
| 52 |
#[inline] |
| 53 |
#[must_use] |
| 54 |
pub fn with_capacityrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]with_capacity().(capacity: usize) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString] { |
| 55 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 56 |
vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(capacity), |
| 57 |
} |
| 58 |
} |
| 59 |
|
| 60 |
/// Creates a new `AsciiString` from a length, capacity and pointer. |
| 61 |
/// |
| 62 |
/// # Safety |
| 63 |
/// |
| 64 |
/// This is highly unsafe, due to the number of invariants that aren't checked: |
| 65 |
/// |
| 66 |
/// * The memory at `buf` need to have been previously allocated by the same allocator this |
| 67 |
/// library uses, with an alignment of 1. |
| 68 |
/// * `length` needs to be less than or equal to `capacity`. |
| 69 |
/// * `capacity` needs to be the correct value. |
| 70 |
/// * `buf` must have `length` valid ascii elements and contain a total of `capacity` total, |
| 71 |
/// possibly, uninitialized, elements. |
| 72 |
/// * Nothing else must be using the memory `buf` points to. |
| 73 |
/// |
| 74 |
/// Violating these may cause problems like corrupting the allocator's internal data structures. |
| 75 |
/// |
| 76 |
/// # Examples |
| 77 |
/// |
| 78 |
/// Basic usage: |
| 79 |
/// |
| 80 |
/// ``` |
| 81 |
/// # use ascii::AsciiString; |
| 82 |
/// use std::mem; |
| 83 |
/// |
| 84 |
/// unsafe { |
| 85 |
/// let mut s = AsciiString::from_ascii("hello").unwrap(); |
| 86 |
/// let ptr = s.as_mut_ptr(); |
| 87 |
/// let len = s.len(); |
| 88 |
/// let capacity = s.capacity(); |
| 89 |
/// |
| 90 |
/// mem::forget(s); |
| 91 |
/// |
| 92 |
/// let s = AsciiString::from_raw_parts(ptr, len, capacity); |
| 93 |
/// |
| 94 |
/// assert_eq!(AsciiString::from_ascii("hello").unwrap(), s); |
| 95 |
/// } |
| 96 |
/// ``` |
| 97 |
#[inline] |
| 98 |
#[must_use] |
| 99 |
pub unsafe fn from_raw_partsrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_raw_parts().(buf: *mut AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#, length: usize, capacity: usize) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString] { |
| 100 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 101 |
// SAFETY: Caller guarantees that `buf` was previously allocated by this library, |
| 102 |
// that `buf` contains `length` valid ascii elements and has a total capacity |
| 103 |
// of `capacity` elements, and that nothing else is using the momory. |
| 104 |
vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec.: unsafe { Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(buf, length, capacity) }, |
| 105 |
} |
| 106 |
} |
| 107 |
|
| 108 |
/// Converts a vector of bytes to an `AsciiString` without checking for non-ASCII characters. |
| 109 |
/// |
| 110 |
/// # Safety |
| 111 |
/// This function is unsafe because it does not check that the bytes passed to it are valid |
| 112 |
/// ASCII characters. If this constraint is violated, it may cause memory unsafety issues with |
| 113 |
/// future of the `AsciiString`, as the rest of this library assumes that `AsciiString`s are |
| 114 |
/// ASCII encoded. |
| 115 |
#[inline] |
| 116 |
#[must_use] |
| 117 |
pub unsafe fn from_ascii_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii_unchecked().<B>(bytes: B) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString] |
| 118 |
where |
| 119 |
B: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 120 |
{ |
| 121 |
let mut bytes = bytes.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().(); |
| 122 |
// SAFETY: The caller guarantees all bytes are valid ascii bytes. |
| 123 |
let ptr = bytes.as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#>(); |
| 124 |
let length = bytes.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 125 |
let capacity = bytes.capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(); |
| 126 |
memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::forgetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/forget().(bytes); |
| 127 |
|
| 128 |
// SAFETY: We guarantee all invariants, as we got the |
| 129 |
// pointer, length and capacity from a `Vec`, |
| 130 |
// and we also guarantee the pointer is valid per |
| 131 |
// the `SAFETY` notice above. |
| 132 |
let vec = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(ptr, length, capacity); |
| 133 |
|
| 134 |
Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString] { vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec. } |
| 135 |
} |
| 136 |
|
| 137 |
/// Converts anything that can represent a byte buffer into an `AsciiString`. |
| 138 |
/// |
| 139 |
/// # Errors |
| 140 |
/// Returns the byte buffer if not all of the bytes are ASCII characters. |
| 141 |
/// |
| 142 |
/// # Examples |
| 143 |
/// ``` |
| 144 |
/// # use ascii::AsciiString; |
| 145 |
/// let foo = AsciiString::from_ascii("foo".to_string()).unwrap(); |
| 146 |
/// let err = AsciiString::from_ascii("Ŋ".to_string()).unwrap_err(); |
| 147 |
/// assert_eq!(foo.as_str(), "foo"); |
| 148 |
/// assert_eq!(err.into_source(), "Ŋ"); |
| 149 |
/// ``` |
| 150 |
pub fn from_asciirust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii().<B>(bytes: B) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<B>> |
| 151 |
where |
| 152 |
B: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>> + AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]>, |
| 153 |
{ |
| 154 |
match bytes.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().().as_ascii_strrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[`[u8]`][AsAsciiStr]as_ascii_str().() { |
| 155 |
// SAFETY: `as_ascii_str` guarantees all bytes are valid ascii bytes. |
| 156 |
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#(unsafe { AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_ascii_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii_unchecked().(bytes) }), |
| 157 |
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#(FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { |
| 158 |
errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error.: e, |
| 159 |
ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner.: bytes, |
| 160 |
}), |
| 161 |
} |
| 162 |
} |
| 163 |
|
| 164 |
/// Pushes the given ASCII string onto this ASCII string buffer. |
| 165 |
/// |
| 166 |
/// # Examples |
| 167 |
/// ``` |
| 168 |
/// # use ascii::{AsciiString, AsAsciiStr}; |
| 169 |
/// use std::str::FromStr; |
| 170 |
/// let mut s = AsciiString::from_str("foo").unwrap(); |
| 171 |
/// s.push_str("bar".as_ascii_str().unwrap()); |
| 172 |
/// assert_eq!(s, "foobar".as_ascii_str().unwrap()); |
| 173 |
/// ``` |
| 174 |
#[inline] |
| 175 |
pub fn push_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push_str().(&mut self, string: &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) { |
| 176 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(string.charsrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]chars().()); |
| 177 |
} |
| 178 |
|
| 179 |
/// Inserts the given ASCII string at the given place in this ASCII string buffer. |
| 180 |
/// |
| 181 |
/// # Panics |
| 182 |
/// |
| 183 |
/// Panics if `idx` is larger than the `AsciiString`'s length. |
| 184 |
/// |
| 185 |
/// # Examples |
| 186 |
/// ``` |
| 187 |
/// # use ascii::{AsciiString, AsAsciiStr}; |
| 188 |
/// use std::str::FromStr; |
| 189 |
/// let mut s = AsciiString::from_str("abc").unwrap(); |
| 190 |
/// s.insert_str(1, "def".as_ascii_str().unwrap()); |
| 191 |
/// assert_eq!(&*s, "adefbc"); |
| 192 |
#[inline] |
| 193 |
pub fn insert_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]insert_str().(&mut self, idx: usize, string: &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) { |
| 194 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(string.lenrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]len().()); |
| 195 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..splicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]splice().(idx..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#idx, string.into_iterrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[`&'a AsciiStr`][IntoIterator]into_iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().()); |
| 196 |
} |
| 197 |
|
| 198 |
/// Returns the number of bytes that this ASCII string buffer can hold without reallocating. |
| 199 |
/// |
| 200 |
/// # Examples |
| 201 |
/// ``` |
| 202 |
/// # use ascii::AsciiString; |
| 203 |
/// let s = String::with_capacity(10); |
| 204 |
/// assert!(s.capacity() >= 10); |
| 205 |
/// ``` |
| 206 |
#[inline] |
| 207 |
#[must_use] |
| 208 |
pub fn capacityrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]capacity().(&self) -> usize { |
| 209 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().() |
| 210 |
} |
| 211 |
|
| 212 |
/// Reserves capacity for at least `additional` more bytes to be inserted in the given |
| 213 |
/// `AsciiString`. The collection may reserve more space to avoid frequent reallocations. |
| 214 |
/// |
| 215 |
/// # Panics |
| 216 |
/// Panics if the new capacity overflows `usize`. |
| 217 |
/// |
| 218 |
/// # Examples |
| 219 |
/// ``` |
| 220 |
/// # use ascii::AsciiString; |
| 221 |
/// let mut s = AsciiString::new(); |
| 222 |
/// s.reserve(10); |
| 223 |
/// assert!(s.capacity() >= 10); |
| 224 |
/// ``` |
| 225 |
#[inline] |
| 226 |
pub fn reserverust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]reserve().(&mut self, additional: usize) { |
| 227 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..reserverust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve().(additional); |
| 228 |
} |
| 229 |
|
| 230 |
/// Reserves the minimum capacity for exactly `additional` more bytes to be inserted in the |
| 231 |
/// given `AsciiString`. Does nothing if the capacity is already sufficient. |
| 232 |
/// |
| 233 |
/// Note that the allocator may give the collection more space than it requests. Therefore |
| 234 |
/// capacity can not be relied upon to be precisely minimal. Prefer `reserve` if future |
| 235 |
/// insertions are expected. |
| 236 |
/// |
| 237 |
/// # Panics |
| 238 |
/// Panics if the new capacity overflows `usize`. |
| 239 |
/// |
| 240 |
/// # Examples |
| 241 |
/// ``` |
| 242 |
/// # use ascii::AsciiString; |
| 243 |
/// let mut s = AsciiString::new(); |
| 244 |
/// s.reserve_exact(10); |
| 245 |
/// assert!(s.capacity() >= 10); |
| 246 |
/// ``` |
| 247 |
#[inline] |
| 248 |
|
| 249 |
pub fn reserve_exactrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]reserve_exact().(&mut self, additional: usize) { |
| 250 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..reserve_exactrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]reserve_exact().(additional); |
| 251 |
} |
| 252 |
|
| 253 |
/// Shrinks the capacity of this ASCII string buffer to match it's length. |
| 254 |
/// |
| 255 |
/// # Examples |
| 256 |
/// ``` |
| 257 |
/// # use ascii::AsciiString; |
| 258 |
/// use std::str::FromStr; |
| 259 |
/// let mut s = AsciiString::from_str("foo").unwrap(); |
| 260 |
/// s.reserve(100); |
| 261 |
/// assert!(s.capacity() >= 100); |
| 262 |
/// s.shrink_to_fit(); |
| 263 |
/// assert_eq!(s.capacity(), 3); |
| 264 |
/// ``` |
| 265 |
#[inline] |
| 266 |
|
| 267 |
pub fn shrink_to_fitrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]shrink_to_fit().(&mut self) { |
| 268 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..shrink_to_fitrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]shrink_to_fit().(); |
| 269 |
} |
| 270 |
|
| 271 |
/// Adds the given ASCII character to the end of the ASCII string. |
| 272 |
/// |
| 273 |
/// # Examples |
| 274 |
/// ``` |
| 275 |
/// # use ascii::{ AsciiChar, AsciiString}; |
| 276 |
/// let mut s = AsciiString::from_ascii("abc").unwrap(); |
| 277 |
/// s.push(AsciiChar::from_ascii('1').unwrap()); |
| 278 |
/// s.push(AsciiChar::from_ascii('2').unwrap()); |
| 279 |
/// s.push(AsciiChar::from_ascii('3').unwrap()); |
| 280 |
/// assert_eq!(s, "abc123"); |
| 281 |
/// ``` |
| 282 |
#[inline] |
| 283 |
|
| 284 |
pub fn pushrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push().(&mut self, ch: AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#) { |
| 285 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(ch); |
| 286 |
} |
| 287 |
|
| 288 |
/// Shortens a ASCII string to the specified length. |
| 289 |
/// |
| 290 |
/// # Panics |
| 291 |
/// Panics if `new_len` > current length. |
| 292 |
/// |
| 293 |
/// # Examples |
| 294 |
/// ``` |
| 295 |
/// # use ascii::AsciiString; |
| 296 |
/// let mut s = AsciiString::from_ascii("hello").unwrap(); |
| 297 |
/// s.truncate(2); |
| 298 |
/// assert_eq!(s, "he"); |
| 299 |
/// ``` |
| 300 |
#[inline] |
| 301 |
|
| 302 |
pub fn truncaterust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]truncate().(&mut self, new_len: usize) { |
| 303 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..truncaterust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]truncate().(new_len); |
| 304 |
} |
| 305 |
|
| 306 |
/// Removes the last character from the ASCII string buffer and returns it. |
| 307 |
/// Returns `None` if this string buffer is empty. |
| 308 |
/// |
| 309 |
/// # Examples |
| 310 |
/// ``` |
| •311 |
/// # #![allow(bindings_with_variant_name)] |
| 312 |
/// # use ascii::AsciiString; |
| 313 |
/// let mut s = AsciiString::from_ascii("foo").unwrap(); |
| 314 |
/// assert_eq!(s.pop().map(|c| c.as_char()), Some('o')); |
| 315 |
/// assert_eq!(s.pop().map(|c| c.as_char()), Some('o')); |
| 316 |
/// assert_eq!(s.pop().map(|c| c.as_char()), Some('f')); |
| 317 |
/// assert_eq!(s.pop(), None); |
| 318 |
/// ``` |
| 319 |
#[inline] |
| 320 |
#[must_use] |
| 321 |
pub fn poprust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]pop().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#> { |
| 322 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() |
| 323 |
} |
| 324 |
|
| 325 |
/// Removes the ASCII character at position `idx` from the buffer and returns it. |
| 326 |
/// |
| 327 |
/// # Warning |
| 328 |
/// This is an O(n) operation as it requires copying every element in the buffer. |
| 329 |
/// |
| 330 |
/// # Panics |
| 331 |
/// If `idx` is out of bounds this function will panic. |
| 332 |
/// |
| 333 |
/// # Examples |
| 334 |
/// ``` |
| 335 |
/// # use ascii::AsciiString; |
| 336 |
/// let mut s = AsciiString::from_ascii("foo").unwrap(); |
| 337 |
/// assert_eq!(s.remove(0).as_char(), 'f'); |
| 338 |
/// assert_eq!(s.remove(1).as_char(), 'o'); |
| 339 |
/// assert_eq!(s.remove(0).as_char(), 'o'); |
| 340 |
/// ``` |
| 341 |
#[inline] |
| 342 |
#[must_use] |
| 343 |
pub fn removerust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]remove().(&mut self, idx: usize) -> AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar# { |
| 344 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..removerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]remove().(idx) |
| 345 |
} |
| 346 |
|
| 347 |
/// Inserts an ASCII character into the buffer at position `idx`. |
| 348 |
/// |
| 349 |
/// # Warning |
| 350 |
/// This is an O(n) operation as it requires copying every element in the buffer. |
| 351 |
/// |
| 352 |
/// # Panics |
| 353 |
/// If `idx` is out of bounds this function will panic. |
| 354 |
/// |
| 355 |
/// # Examples |
| 356 |
/// ``` |
| 357 |
/// # use ascii::{AsciiString,AsciiChar}; |
| 358 |
/// let mut s = AsciiString::from_ascii("foo").unwrap(); |
| 359 |
/// s.insert(2, AsciiChar::b); |
| 360 |
/// assert_eq!(s, "fobo"); |
| 361 |
/// ``` |
| 362 |
#[inline] |
| 363 |
|
| 364 |
pub fn insertrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]insert().(&mut self, idx: usize, ch: AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#) { |
| 365 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]insert().(idx, ch); |
| 366 |
} |
| 367 |
|
| 368 |
/// Returns the number of bytes in this ASCII string. |
| 369 |
/// |
| 370 |
/// # Examples |
| 371 |
/// ``` |
| 372 |
/// # use ascii::AsciiString; |
| 373 |
/// let s = AsciiString::from_ascii("foo").unwrap(); |
| 374 |
/// assert_eq!(s.len(), 3); |
| 375 |
/// ``` |
| 376 |
#[inline] |
| 377 |
#[must_use] |
| 378 |
pub fn lenrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]len().(&self) -> usize { |
| 379 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() |
| 380 |
} |
| 381 |
|
| 382 |
/// Returns true if the ASCII string contains zero bytes. |
| 383 |
/// |
| 384 |
/// # Examples |
| 385 |
/// ``` |
| 386 |
/// # use ascii::{AsciiChar, AsciiString}; |
| 387 |
/// let mut s = AsciiString::new(); |
| 388 |
/// assert!(s.is_empty()); |
| 389 |
/// s.push(AsciiChar::from_ascii('a').unwrap()); |
| 390 |
/// assert!(!s.is_empty()); |
| 391 |
/// ``` |
| 392 |
#[inline] |
| 393 |
#[must_use] |
| 394 |
pub fn is_emptyrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]is_empty().(&self) -> bool { |
| 395 |
self.lenrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]len().() 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 |
| 396 |
} |
| 397 |
|
| 398 |
/// Truncates the ASCII string, setting length (but not capacity) to zero. |
| 399 |
/// |
| 400 |
/// # Examples |
| 401 |
/// ``` |
| 402 |
/// # use ascii::AsciiString; |
| 403 |
/// let mut s = AsciiString::from_ascii("foo").unwrap(); |
| 404 |
/// s.clear(); |
| 405 |
/// assert!(s.is_empty()); |
| 406 |
/// ``` |
| 407 |
#[inline] |
| 408 |
|
| 409 |
pub fn clearrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]clear().(&mut self) { |
| 410 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..clearrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]clear().(); |
| 411 |
} |
| 412 |
|
| 413 |
/// Converts this [`AsciiString`] into a [`Box`]`<`[`AsciiStr`]`>`. |
| 414 |
/// |
| 415 |
/// This will drop any excess capacity |
| 416 |
#[inline] |
| 417 |
#[must_use] |
| 418 |
pub fn into_boxed_ascii_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]into_boxed_ascii_str().(self) -> Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 419 |
let slice = self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..into_boxed_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]into_boxed_slice().(); |
| 420 |
Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::fromrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[`Box<AsciiStr>`][`From<Box<[AsciiChar]>>`]from().(slice) |
| 421 |
} |
| 422 |
} |
| 423 |
|
| 424 |
impl Derefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/Deref# for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 425 |
type Targetrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]Target# = AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#; |
| 426 |
|
| 427 |
#[inline] |
| 428 |
fn derefrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().(&self) -> &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 429 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..as_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_slice().().as_refrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[`[AsciiChar]`][`AsRef<AsciiStr>`]as_ref().() |
| 430 |
} |
| 431 |
} |
| 432 |
|
| 433 |
impl DerefMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/DerefMut# for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 434 |
#[inline] |
| 435 |
fn deref_mutrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][DerefMut]deref_mut().(&mut self) -> &mut AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 436 |
self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..as_mut_slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_slice().().as_mutrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[`[AsciiChar]`][`AsMut<AsciiStr>`]as_mut().() |
| 437 |
} |
| 438 |
} |
| 439 |
|
| 440 |
impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<str> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 441 |
#[inline] |
| 442 |
fn eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`PartialEq<str>`]eq().(&self, other: &str) -> bool { |
| 443 |
*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self rust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][`PartialEq<str>`]eq().==rust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][`PartialEq<str>`]eq(). rust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][`PartialEq<str>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other |
| 444 |
} |
| 445 |
} |
| 446 |
|
| 447 |
impl PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for str { |
| 448 |
#[inline] |
| 449 |
fn eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[str][`PartialEq<AsciiString>`]eq().(&self, other: &AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> bool { |
| 450 |
*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().other rust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][`PartialEq<str>`]eq().==rust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][`PartialEq<str>`]eq(). rust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][`PartialEq<str>`]eq().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self |
| 451 |
} |
| 452 |
} |
| 453 |
|
| 454 |
macro_rules! impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq! { |
| 455 |
($lhs:ty, $rhs:ty) => { |
| 456 |
impl PartialEq<$rhs> for $lhs { |
| 457 |
#[inline] |
| 458 |
fn eq(&self, other: &$rhs) -> bool { |
| 459 |
PartialEq::eq(&**self, &**other) |
| 460 |
} |
| 461 |
} |
| 462 |
}; |
| 463 |
} |
| 464 |
|
| 465 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# } |
| 466 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# } |
| 467 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#, Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# } |
| 468 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# } |
| 469 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#, AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# } |
| 470 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# } |
| 471 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { &str, AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# } |
| 472 |
impl_eqrust-analyzer cargo ascii 1.1.0 ascii_string/impl_eq!! { AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, &str } |
| 473 |
|
| 474 |
impl Borrowrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/Borrow#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 475 |
#[inline] |
| 476 |
fn borrowrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Borrow<AsciiStr>`]borrow().(&self) -> &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 477 |
&*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self |
| 478 |
} |
| 479 |
} |
| 480 |
|
| 481 |
impl BorrowMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core borrow/BorrowMut#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 482 |
#[inline] |
| 483 |
fn borrow_mutrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`BorrowMut<AsciiStr>`]borrow_mut().(&mut self) -> &mut AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 484 |
&mut *rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][DerefMut]deref_mut().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self |
| 485 |
} |
| 486 |
} |
| 487 |
|
| 488 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#>> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 489 |
#[inline] |
| 490 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Vec<AsciiChar>>`]from().(vec: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#>) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Vec<AsciiChar>>`] { |
| 491 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec. } |
| 492 |
} |
| 493 |
} |
| 494 |
|
| 495 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 496 |
#[inline] |
| 497 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<AsciiChar>`]from().(ch: AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<AsciiChar>`] { |
| 498 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ch] } |
| 499 |
} |
| 500 |
} |
| 501 |
|
| 502 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 503 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Vec<u8>`][`From<AsciiString>`]from().(mut s: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8> { |
| 504 |
// SAFETY: All ascii bytes are valid `u8`, as we are `repr(u8)`. |
| 505 |
// Note: We forget `self` to avoid `self.vec` from being deallocated. |
| 506 |
let ptr = s.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..as_mut_ptrrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]as_mut_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/mut_ptr/impl#[`*mut T`]cast().::<u8>(); |
| 507 |
let length = s.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(); |
| 508 |
let capacity = s.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]capacity().(); |
| 509 |
memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::forgetrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/forget().(s); |
| 510 |
|
| 511 |
// SAFETY: We guarantee all invariants due to getting `ptr`, `length` |
| 512 |
// and `capacity` from a `Vec`. We also guarantee `ptr` is valid |
| 513 |
// due to the `SAFETY` block above. |
| 514 |
unsafe { Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::from_raw_partsrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]from_raw_parts().(ptr, length, capacity) } |
| 515 |
} |
| 516 |
} |
| 517 |
|
| 518 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#> { |
| 519 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Vec<AsciiChar>`][`From<AsciiString>`]from().(s: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#> { |
| 520 |
s.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec. |
| 521 |
} |
| 522 |
} |
| 523 |
|
| 524 |
impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 525 |
#[inline] |
| 526 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a AsciiStr>`]from().(s: &'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a AsciiStr>`] { |
| 527 |
s.to_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]to_ascii_string().() |
| 528 |
} |
| 529 |
} |
| 530 |
|
| 531 |
impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a [AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#]> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 532 |
#[inline] |
| 533 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a [AsciiChar]>`]from().(s: &'a [AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#]) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 534 |
s.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#copied().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().() |
| 535 |
} |
| 536 |
} |
| 537 |
|
| 538 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 539 |
#[inline] |
| 540 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[String][`From<AsciiString>`]from().(s: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# { |
| 541 |
// SAFETY: All ascii bytes are `utf8`. |
| 542 |
unsafe { Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::from_utf8_uncheckedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]from_utf8_unchecked().(s.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().()) } |
| 543 |
} |
| 544 |
} |
| 545 |
|
| 546 |
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#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#>> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 547 |
#[inline] |
| 548 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Box<AsciiStr>>`]from().(boxed: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#>) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Box<AsciiStr>>`] { |
| 549 |
boxed.into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]into_ascii_string().() |
| 550 |
} |
| 551 |
} |
| 552 |
|
| 553 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 554 |
#[inline] |
| 555 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Box<AsciiStr>`][`From<AsciiString>`]from().(string: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Box<AsciiStr>`][`From<AsciiString>`] { |
| 556 |
string.into_boxed_ascii_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]into_boxed_ascii_str().() |
| 557 |
} |
| 558 |
} |
| 559 |
|
| 560 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 561 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Rc<AsciiStr>`][`From<AsciiString>`]from().(s: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 562 |
let var: Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#<[AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#]> = s.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 563 |
// SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar] |
| 564 |
unsafe { Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]from_raw().(Rcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/Rc#::into_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc rc/impl#[`Rc<T>`]into_raw().(var) as *const AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) } |
| 565 |
} |
| 566 |
} |
| 567 |
|
| 568 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 569 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Arc<AsciiStr>`][`From<AsciiString>`]from().(s: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 570 |
let var: Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#<[AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#]> = s.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec..intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 571 |
// SAFETY: AsciiStr is repr(transparent) and thus has the same layout as [AsciiChar] |
| 572 |
unsafe { Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::from_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]from_raw().(Arcrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/Arc#::into_rawrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc sync/impl#[`Arc<T>`]into_raw().(var) as *const AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) } |
| 573 |
} |
| 574 |
} |
| 575 |
|
| 576 |
impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#>> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 577 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Cow<'a, AsciiStr>>`]from().(cow: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#>) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 578 |
cow.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().() |
| 579 |
} |
| 580 |
} |
| 581 |
|
| 582 |
impl Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#> for Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 583 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Cow<'static, AsciiStr>`][`From<AsciiString>`]from().(string: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'static, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 584 |
Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(string) |
| 585 |
} |
| 586 |
} |
| 587 |
|
| 588 |
impl<'a> Fromrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/From#<&'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 589 |
fn fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Cow<'a, AsciiStr>`][`From<&'a AsciiStr>`]from().(s: &'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) -> Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> { |
| 590 |
Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(s) |
| 591 |
} |
| 592 |
} |
| 593 |
|
| 594 |
impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 595 |
#[inline] |
| 596 |
fn as_refrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AsRef<AsciiStr>`]as_ref().(&self) -> &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 597 |
&*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#]> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 602 |
#[inline] |
| 603 |
fn as_refrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AsRef<[AsciiChar]>`]as_ref().(&self) -> &[AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#] { |
| 604 |
&self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec. |
| 605 |
} |
| 606 |
} |
| 607 |
|
| 608 |
impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<[u8]> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 609 |
#[inline] |
| 610 |
fn as_refrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AsRef<[u8]>`]as_ref().(&self) -> &[u8] { |
| 611 |
self.as_bytesrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]as_bytes().() |
| 612 |
} |
| 613 |
} |
| 614 |
|
| 615 |
impl AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<str> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 616 |
#[inline] |
| 617 |
fn as_refrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AsRef<str>`]as_ref().(&self) -> &str { |
| 618 |
self.as_strrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]as_str().() |
| 619 |
} |
| 620 |
} |
| 621 |
|
| 622 |
impl AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 623 |
#[inline] |
| 624 |
fn as_mutrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AsMut<AsciiStr>`]as_mut().(&mut self) -> &mut AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 625 |
&mut *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self |
| 626 |
} |
| 627 |
} |
| 628 |
|
| 629 |
impl AsMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsMut#<[AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#]> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 630 |
#[inline] |
| 631 |
fn as_mutrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AsMut<[AsciiChar]>`]as_mut().(&mut self) -> &mut [AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#] { |
| 632 |
&mut self.vecrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#vec. |
| 633 |
} |
| 634 |
} |
| 635 |
|
| 636 |
impl FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr# for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 637 |
type Errrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][FromStr]Err# = AsAsciiStrErrorrust-analyzer cargo ascii 1.1.0 ascii_str/AsAsciiStrError#; |
| 638 |
|
| 639 |
fn from_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][FromStr]from_str().(s: &str) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, AsAsciiStrErrorrust-analyzer cargo ascii 1.1.0 ascii_str/AsAsciiStrError#> { |
| 640 |
s.as_ascii_strrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[str][AsAsciiStr]as_ascii_str().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#::to_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]to_ascii_string().) |
| 641 |
} |
| 642 |
} |
| 643 |
|
| 644 |
impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 645 |
#[inline] |
| 646 |
fn fmtrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 647 |
fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][Display]fmt().(&*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, f) |
| 648 |
} |
| 649 |
} |
| 650 |
|
| 651 |
impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 652 |
#[inline] |
| 653 |
fn fmtrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 654 |
fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#::fmtrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr][Debug]fmt().(&*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self, f) |
| 655 |
} |
| 656 |
} |
| 657 |
|
| 658 |
/// Please note that the `std::fmt::Result` returned by these methods does not support |
| 659 |
/// transmission of an error other than that an error occurred. |
| 660 |
impl fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Write# for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 661 |
fn write_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Write]write_str().(&mut self, s: &str) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 662 |
if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(astr) = AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]from_ascii().(s) { |
| 663 |
self.push_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push_str().(astr); |
| 664 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 665 |
} else { |
| 666 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#) |
| 667 |
} |
| 668 |
} |
| 669 |
|
| 670 |
fn write_charrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Write]write_char().(&mut self, c: char) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 671 |
if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(achar) = AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_char/impl#[AsciiChar]from_ascii().(c) { |
| 672 |
self.pushrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push().(achar); |
| 673 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 674 |
} else { |
| 675 |
Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Error#) |
| 676 |
} |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
impl<A: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#>> FromIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/FromIterator#<A> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 681 |
fn from_iterrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`FromIterator<A>`]from_iter().<I: 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>>(iter: I) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 682 |
let mut buf = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::newrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]new().(); |
| 683 |
buf.extendrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Extend<A>`]extend().(iter); |
| 684 |
buf |
| 685 |
} |
| 686 |
} |
| 687 |
|
| 688 |
impl<A: AsRefrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#>> Extendrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/Extend#<A> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 689 |
fn extendrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Extend<A>`]extend().<I: 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>>(&mut self, iterable: I) { |
| 690 |
let iterator = iterable.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().(); |
| 691 |
let (lower_bound, _) = iterator.size_hintrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#size_hint().(); |
| 692 |
self.reserverust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]reserve().(lower_bound); |
| 693 |
for item in iterator { |
| 694 |
self.push_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push_str().(item.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/AsRef#as_ref().()); |
| 695 |
} |
| 696 |
} |
| 697 |
} |
| 698 |
|
| 699 |
impl<'a> Addrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/Add#<&'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 700 |
type Outputrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Add<&'a AsciiStr>`]Output# = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#; |
| 701 |
|
| 702 |
#[inline] |
| 703 |
fn addrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Add<&'a AsciiStr>`]add().(mut self, other: &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 704 |
self.push_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push_str().(other); |
| 705 |
self |
| 706 |
} |
| 707 |
} |
| 708 |
|
| 709 |
impl<'a> AddAssignrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/AddAssign#<&'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 710 |
#[inline] |
| 711 |
fn add_assignrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`AddAssign<&'a AsciiStr>`]add_assign().(&mut self, other: &AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#) { |
| 712 |
self.push_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]push_str().(other); |
| 713 |
} |
| 714 |
} |
| 715 |
|
| 716 |
#[allow(clippy::indexing_slicing)] // In `Index`, if it's out of bounds, panic is the default |
| 717 |
impl<T> Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<T> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# |
| 718 |
where |
| 719 |
AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#: Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<T>, |
| 720 |
{ |
| 721 |
type Outputrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Index<T>`]Output# = <AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# as Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<T>>::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output#; |
| 722 |
|
| 723 |
#[inline] |
| 724 |
fn indexrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`Index<T>`]index().(&self, index: T) -> &<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# as Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<T>>::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# { |
| 725 |
&(*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Deref]deref().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self)[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). |
| 726 |
} |
| 727 |
} |
| 728 |
|
| 729 |
#[allow(clippy::indexing_slicing)] // In `IndexMut`, if it's out of bounds, panic is the default |
| 730 |
impl<T> IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<T> for AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# |
| 731 |
where |
| 732 |
AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#: IndexMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#<T>, |
| 733 |
{ |
| 734 |
#[inline] |
| 735 |
fn index_mutrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`IndexMut<T>`]index_mut().(&mut self, index: T) -> &mut <AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# as Indexrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#<T>>::Outputrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#Output# { |
| 736 |
&mut (*rust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][DerefMut]deref_mut().*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&mut T`][Deref]deref().self)[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). |
| 737 |
} |
| 738 |
} |
| 739 |
|
| 740 |
/// A possible error value when converting an `AsciiString` from a byte vector or string. |
| 741 |
/// It wraps an `AsAsciiStrError` which you can get through the `ascii_error()` method. |
| 742 |
/// |
| 743 |
/// This is the error type for `AsciiString::from_ascii()` and |
| 744 |
/// `IntoAsciiString::into_ascii_string()`. They will never clone or touch the content of the |
| 745 |
/// original type; It can be extracted by the `into_source` method. |
| 746 |
/// |
| 747 |
/// #Examples |
| 748 |
/// ``` |
| 749 |
/// # use ascii::IntoAsciiString; |
| 750 |
/// let err = "bø!".to_string().into_ascii_string().unwrap_err(); |
| 751 |
/// assert_eq!(err.ascii_error().valid_up_to(), 1); |
| 752 |
/// assert_eq!(err.into_source(), "bø!".to_string()); |
| 753 |
/// ``` |
| 754 |
#[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:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)] |
| 755 |
pub struct FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<O> { |
| 756 |
errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error.: AsAsciiStrErrorrust-analyzer cargo ascii 1.1.0 ascii_str/AsAsciiStrError#, |
| 757 |
ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner.: O, |
| 758 |
} |
| 759 |
impl<O> FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<O> { |
| 760 |
/// Get the position of the first non-ASCII byte or character. |
| 761 |
#[inline] |
| 762 |
#[must_use] |
| 763 |
pub fn ascii_errorrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`]ascii_error().(&self) -> AsAsciiStrErrorrust-analyzer cargo ascii 1.1.0 ascii_str/AsAsciiStrError# { |
| 764 |
self.errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error. |
| 765 |
} |
| 766 |
/// Get back the original, unmodified type. |
| 767 |
#[inline] |
| 768 |
#[must_use] |
| 769 |
pub fn into_sourcerust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`]into_source().(self) -> O { |
| 770 |
self.ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner. |
| 771 |
} |
| 772 |
} |
| 773 |
impl<O> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<O> { |
| 774 |
#[inline] |
| 775 |
fn fmtrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`][Debug]fmt().(&self, fmtr: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 776 |
fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug#::fmtrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsAsciiStrError][Debug]fmt().(&self.errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., fmtr) |
| 777 |
} |
| 778 |
} |
| 779 |
impl<O> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<O> { |
| 780 |
#[inline] |
| 781 |
fn fmtrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`][Display]fmt().(&self, fmtr: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 782 |
fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display#::fmtrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsAsciiStrError][Display]fmt().(&self.errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., fmtr) |
| 783 |
} |
| 784 |
} |
| 785 |
#[cfg(feature = "std")] |
| 786 |
impl<O: Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#> Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<O> { |
| 787 |
#[inline] |
| 788 |
#[allow(deprecated)] // TODO: Remove deprecation once the earliest version we support deprecates this method. |
| 789 |
fn descriptionrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`][Error]description().(&self) -> &str { |
| 790 |
self.errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error..descriptionrust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsAsciiStrError][Error]description().() |
| 791 |
} |
| 792 |
/// Always returns an `AsAsciiStrError` |
| 793 |
fn causerust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`][Error]cause().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#> { |
| 794 |
Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(&self.errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error. as &dyn Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#) |
| 795 |
} |
| 796 |
} |
| 797 |
|
| 798 |
/// Convert vectors into `AsciiString`. |
| 799 |
pub trait IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#: Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized# { |
| 800 |
/// Convert to `AsciiString` without checking for non-ASCII characters. |
| 801 |
/// |
| 802 |
/// # Safety |
| 803 |
/// If `self` contains non-ascii characters, calling this function is |
| 804 |
/// undefined behavior. |
| 805 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#; |
| 806 |
|
| 807 |
/// Convert to `AsciiString`. |
| 808 |
/// |
| 809 |
/// # Errors |
| 810 |
/// If `self` contains non-ascii characters, this will return `Err` |
| 811 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Self>>; |
| 812 |
} |
| 813 |
|
| 814 |
impl IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString# for Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#> { |
| 815 |
#[inline] |
| 816 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Vec<AsciiChar>`][IntoAsciiString]into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 817 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Vec<AsciiChar>>`]from().(self) |
| 818 |
} |
| 819 |
#[inline] |
| 820 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Vec<AsciiChar>`][IntoAsciiString]into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Vec<AsciiChar>`][IntoAsciiString]>> { |
| 821 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Vec<AsciiChar>>`]from().(self)) |
| 822 |
} |
| 823 |
} |
| 824 |
|
| 825 |
impl<'a> IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString# for &'a [AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#] { |
| 826 |
#[inline] |
| 827 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a [AsciiChar]`][IntoAsciiString]into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 828 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a [AsciiChar]>`]from().(self) |
| 829 |
} |
| 830 |
#[inline] |
| 831 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a [AsciiChar]`][IntoAsciiString]into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a [AsciiChar]`][IntoAsciiString]>> { |
| 832 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a [AsciiChar]>`]from().(self)) |
| 833 |
} |
| 834 |
} |
| 835 |
|
| 836 |
impl<'a> IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString# for &'a AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr# { |
| 837 |
#[inline] |
| 838 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a AsciiStr`][IntoAsciiString]into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 839 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a AsciiStr>`]from().(self) |
| 840 |
} |
| 841 |
#[inline] |
| 842 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a AsciiStr`][IntoAsciiString]into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a AsciiStr`][IntoAsciiString]>> { |
| 843 |
Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<&'a AsciiStr>`]from().(self)) |
| 844 |
} |
| 845 |
} |
| 846 |
|
| 847 |
macro_rules! impl_into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl_into_ascii_string! { |
| 848 |
('a, $wider:ty) => { |
| 849 |
impl<'a> IntoAsciiString for $wider { |
| 850 |
#[inline] |
| 851 |
unsafe fn into_ascii_string_unchecked(self) -> AsciiString { |
| 852 |
// SAFETY: Caller guarantees `self` only has valid ascii bytes |
| 853 |
unsafe { AsciiString::from_ascii_unchecked(self) } |
| 854 |
} |
| 855 |
|
| 856 |
#[inline] |
| 857 |
fn into_ascii_string(self) -> Result<AsciiString, FromAsciiError<Self>> { |
| 858 |
AsciiString::from_ascii(self) |
| 859 |
} |
| 860 |
} |
| 861 |
}; |
| 862 |
|
| 863 |
($wider:ty) => { |
| 864 |
impl IntoAsciiString for $wider { |
| 865 |
#[inline] |
| 866 |
unsafe fn into_ascii_string_unchecked(self) -> AsciiString { |
| 867 |
// SAFETY: Caller guarantees `self` only has valid ascii bytes |
| 868 |
unsafe { AsciiString::from_ascii_unchecked(self) } |
| 869 |
} |
| 870 |
|
| 871 |
#[inline] |
| 872 |
fn into_ascii_string(self) -> Result<AsciiString, FromAsciiError<Self>> { |
| 873 |
AsciiString::from_ascii(self) |
| 874 |
} |
| 875 |
} |
| 876 |
}; |
| 877 |
} |
| 878 |
|
| 879 |
impl_into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl_into_ascii_string!! {AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#} |
| 880 |
impl_into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl_into_ascii_string!! {Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>} |
| 881 |
impl_into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl_into_ascii_string!! {'a, &'a [u8]} |
| 882 |
impl_into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl_into_ascii_string!! {Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#} |
| 883 |
impl_into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl_into_ascii_string!! {'a, &'a str} |
| 884 |
|
| 885 |
/// # Notes |
| 886 |
/// The trailing null byte `CString` has will be removed during this conversion. |
| 887 |
#[cfg(feature = "std")] |
| 888 |
impl IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString# for CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString# { |
| 889 |
#[inline] |
| 890 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[CString][IntoAsciiString]into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 891 |
// SAFETY: Caller guarantees `self` only has valid ascii bytes |
| 892 |
unsafe { AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_ascii_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii_unchecked().(self.into_bytesrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]into_bytes().()) } |
| 893 |
} |
| 894 |
|
| 895 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[CString][IntoAsciiString]into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[CString][IntoAsciiString]>> { |
| 896 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii().(self.into_bytes_with_nulrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]into_bytes_with_nul().()) |
| 897 |
.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner. }| { |
| 898 |
FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { |
| 899 |
// SAFETY: We don't discard the NULL byte from the original |
| 900 |
// string, so we ensure that it's null terminated |
| 901 |
ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner.: unsafe { CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::from_vec_uncheckedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]from_vec_unchecked().(owner) }, |
| 902 |
errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., |
| 903 |
} |
| 904 |
}) |
| 905 |
.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|mut s| { |
| 906 |
let nul = s.poprust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]pop().(); |
| 907 |
debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(nul, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::Nullrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#Null#)); |
| 908 |
s |
| 909 |
}) |
| 910 |
} |
| 911 |
} |
| 912 |
|
| 913 |
/// Note that the trailing null byte will be removed in the conversion. |
| 914 |
#[cfg(feature = "std")] |
| 915 |
impl<'a> IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString# for &'a CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr# { |
| 916 |
#[inline] |
| 917 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a CStr`][IntoAsciiString]into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 918 |
// SAFETY: Caller guarantees `self` only has valid ascii bytes |
| 919 |
unsafe { AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_ascii_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii_unchecked().(self.to_bytesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_bytes().()) } |
| 920 |
} |
| 921 |
|
| 922 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a CStr`][IntoAsciiString]into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a CStr`][IntoAsciiString]>> { |
| 923 |
AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii().(self.to_bytes_with_nulrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]to_bytes_with_nul().()) |
| 924 |
.map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner. }| FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { |
| 925 |
// SAFETY: We don't discard the NULL byte from the original |
| 926 |
// string, so we ensure that it's null terminated |
| 927 |
ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner.: unsafe { CStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/CStr#::from_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ffi/c_str/impl#[CStr]from_ptr().(owner.as_ptrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]as_ptr().().castrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ptr/const_ptr/impl#[`*const T`]cast().()) }, |
| 928 |
errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., |
| 929 |
}) |
| 930 |
.maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map().(|mut s| { |
| 931 |
let nul = s.poprust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]pop().(); |
| 932 |
debug_assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/debug_assert_eq!!(nul, Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::Nullrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#Null#)); |
| 933 |
s |
| 934 |
}) |
| 935 |
} |
| 936 |
} |
| 937 |
|
| 938 |
impl<'a, B> IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString# for Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'a, B> |
| 939 |
where |
| 940 |
B: 'a + ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned# + ?Sizedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Sized#, |
| 941 |
&'a B: IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#, |
| 942 |
<B as ToOwnedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#>::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/ToOwned#Owned#: IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#, |
| 943 |
{ |
| 944 |
#[inline] |
| 945 |
unsafe fn into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Cow<'a, B>`][IntoAsciiString]into_ascii_string_unchecked().(self) -> AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# { |
| 946 |
// SAFETY: Caller guarantees `self` only has valid ascii bytes |
| 947 |
unsafe { IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#::into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#into_ascii_string_unchecked().(self.into_ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/impl#[`Cow<'_, B>`]into_owned().()) } |
| 948 |
} |
| 949 |
|
| 950 |
fn into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Cow<'a, B>`][IntoAsciiString]into_ascii_string().(self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#<Selfrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Cow<'a, B>`][IntoAsciiString]>> { |
| 951 |
match self { |
| 952 |
Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(b) => { |
| 953 |
IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#::into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#into_ascii_string().(b).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner. }| { |
| 954 |
FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { |
| 955 |
ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(owner), |
| 956 |
errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., |
| 957 |
} |
| 958 |
}) |
| 959 |
} |
| 960 |
Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(b) => { |
| 961 |
IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#::into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#into_ascii_string().(b).map_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]map_err().(|FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner. }| { |
| 962 |
FromAsciiErrorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError# { |
| 963 |
ownerrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#owner.: Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(owner), |
| 964 |
errorrust-analyzer cargo ascii 1.1.0 ascii_string/FromAsciiError#error., |
| 965 |
} |
| 966 |
}) |
| 967 |
} |
| 968 |
} |
| 969 |
} |
| 970 |
} |
| 971 |
|
| 972 |
#[cfg(test)] |
| 973 |
mod testsrust-analyzer cargo ascii 1.1.0 ascii_string/tests/ { |
| 974 |
use superrust-analyzer cargo ascii 1.1.0 ascii_string/::{AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#, IntoAsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/IntoAsciiString#}; |
| 975 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::FromStrrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/traits/FromStr#; |
| 976 |
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#, ToStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/ToString#}; |
| 977 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/::Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#; |
| 978 |
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#; |
| 979 |
#[cfg(feature = "std")] |
| 980 |
use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::ffirust-analyzer cargo std https://github.com/rust-lang/rust/library/std ffi/::CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#; |
| 981 |
use {AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#, AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#}; |
| 982 |
|
| 983 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 984 |
fn into_stringrust-analyzer cargo ascii 1.1.0 ascii_string/tests/into_string().() { |
| 985 |
let v = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii().(&[40_u8, 32, 59][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 986 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(v), "( ;".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 987 |
} |
| 988 |
|
| 989 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 990 |
fn into_bytesrust-analyzer cargo ascii 1.1.0 ascii_string/tests/into_bytes().() { |
| 991 |
let v = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]from_ascii().(&[40_u8, 32, 59][rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index()...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFull#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/impl#[`[T; N]`][`Index<I>`]index().).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 992 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>::intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(v), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![40_u8, 32, 59]); |
| 993 |
} |
| 994 |
|
| 995 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 996 |
fn from_ascii_vecrust-analyzer cargo ascii 1.1.0 ascii_string/tests/from_ascii_vec().() { |
| 997 |
let vec = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![ |
| 998 |
AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_char/impl#[AsciiChar]from_ascii().('A').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 999 |
AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::from_asciirust-analyzer cargo ascii 1.1.0 ascii_char/impl#[AsciiChar]from_ascii().('B').unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(), |
| 1000 |
]; |
| 1001 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][`From<Vec<AsciiChar>>`]from().(vec), AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::from_strrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][FromStr]from_str().("AB").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().()); |
| 1002 |
} |
| 1003 |
|
| 1004 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1005 |
#[cfg(feature = "std")] |
| 1006 |
fn from_cstringrust-analyzer cargo ascii 1.1.0 ascii_string/tests/from_cstring().() { |
| 1007 |
let cstring = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().("baz").unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1008 |
let ascii_str = cstring.clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString][Clone]clone().().into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[CString][IntoAsciiString]into_ascii_string().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1009 |
let expected_chars = &[AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::brust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#b#, AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::arust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#a#, AsciiCharrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#::zrust-analyzer cargo ascii 1.1.0 ascii_char/AsciiChar#z#]; |
| 1010 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ascii_str.lenrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]len().(), 3); |
| 1011 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ascii_str.as_slicerust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]as_slice().(), expected_chars); |
| 1012 |
|
| 1013 |
// SAFETY: "baz" only contains valid ascii characters. |
| 1014 |
let ascii_str_unchecked = unsafe { cstring.into_ascii_string_uncheckedrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[CString][IntoAsciiString]into_ascii_string_unchecked().() }; |
| 1015 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ascii_str_unchecked.lenrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]len().(), 3); |
| 1016 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ascii_str_unchecked.as_slicerust-analyzer cargo ascii 1.1.0 ascii_str/impl#[AsciiStr]as_slice().(), expected_chars); |
| 1017 |
|
| 1018 |
let sparkle_heart_bytes = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![240_u8, 159, 146, 150]; |
| 1019 |
let cstring = CStringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/CString#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString]new().(sparkle_heart_bytes).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1020 |
let cstr = &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString][Deref]deref().cstring; |
| 1021 |
let ascii_err = cstr.into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a CStr`][IntoAsciiString]into_ascii_string().().unwrap_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_err().(); |
| 1022 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(ascii_err.into_sourcerust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`FromAsciiError<O>`]into_source().(), &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc ffi/c_str/impl#[CString][Deref]deref().cstring); |
| 1023 |
} |
| 1024 |
|
| 1025 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1026 |
#[cfg(feature = "std")] |
| 1027 |
fn fmt_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/tests/fmt_ascii_string().() { |
| 1028 |
let s = "abc".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[String][IntoAsciiString]into_ascii_string().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1029 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{}", s), "abc".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1030 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("{:?}", s), "\"abc\"".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()); |
| 1031 |
} |
| 1032 |
|
| 1033 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1034 |
fn write_fmtrust-analyzer cargo ascii 1.1.0 ascii_string/tests/write_fmt().() { |
| 1035 |
use allocrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc crate/::{fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/, strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/}; |
| 1036 |
|
| 1037 |
let mut s0 = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::newrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]new().(); |
| 1038 |
fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/write().(&mut s0, format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("Hello World")).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1039 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s0, "Hello World"); |
| 1040 |
|
| 1041 |
let mut s1 = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::newrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]new().(); |
| 1042 |
fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/write().(&mut s1, format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("{}", 9)).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1043 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(s1, "9"); |
| 1044 |
|
| 1045 |
let mut s2 = AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString#::newrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString]new().(); |
| 1046 |
let sparkle_heart_bytes = [240, 159, 146, 150]; |
| 1047 |
let sparkle_heart = strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(&sparkle_heart_bytes).unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1048 |
assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/write().(&mut s2, format_argsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/format_args!!("{}", sparkle_heart)).is_errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]is_err().()); |
| 1049 |
} |
| 1050 |
|
| 1051 |
#[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 1052 |
fn to_and_from_boxrust-analyzer cargo ascii 1.1.0 ascii_string/tests/to_and_from_box().() { |
| 1053 |
let string = "abc".into_ascii_stringrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`&'a str`][IntoAsciiString]into_ascii_string().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap().(); |
| 1054 |
let converted: Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#<AsciiStrrust-analyzer cargo ascii 1.1.0 ascii_str/AsciiStr#> = Boxrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc boxed/Box#::fromrust-analyzer cargo ascii 1.1.0 ascii_string/impl#[`Box<AsciiStr>`][`From<AsciiString>`]from().(string.clonerust-analyzer cargo ascii 1.1.0 ascii_string/impl#[AsciiString][Clone]clone().()); |
| 1055 |
let converted: AsciiStringrust-analyzer cargo ascii 1.1.0 ascii_string/AsciiString# = converted.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`Into<U>`]into().(); |
| 1056 |
assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(string, converted); |
| 1057 |
} |
| 1058 |
} |