Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'lib/smol_str/src/lib.rs')
-rw-r--r--lib/smol_str/src/lib.rs62
1 files changed, 15 insertions, 47 deletions
diff --git a/lib/smol_str/src/lib.rs b/lib/smol_str/src/lib.rs
index ded07c61c6..effaba211d 100644
--- a/lib/smol_str/src/lib.rs
+++ b/lib/smol_str/src/lib.rs
@@ -115,10 +115,7 @@ impl Clone for SmolStr {
impl Default for SmolStr {
#[inline(always)]
fn default() -> SmolStr {
- SmolStr(Repr::Inline {
- len: InlineSize::_V0,
- buf: [0; INLINE_CAP],
- })
+ SmolStr(Repr::Inline { len: InlineSize::_V0, buf: [0; INLINE_CAP] })
}
}
@@ -216,13 +213,13 @@ impl hash::Hash for SmolStr {
}
impl fmt::Debug for SmolStr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Debug::fmt(self.as_str(), f)
}
}
impl fmt::Display for SmolStr {
- fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt::Display::fmt(self.as_str(), f)
}
}
@@ -245,11 +242,8 @@ fn from_buf_and_chars(
) -> SmolStr {
let min_size = iter.size_hint().0 + buf_len;
if min_size > INLINE_CAP {
- let heap: String = core::str::from_utf8(&buf[..buf_len])
- .unwrap()
- .chars()
- .chain(iter)
- .collect();
+ let heap: String =
+ core::str::from_utf8(&buf[..buf_len]).unwrap().chars().chain(iter).collect();
if heap.len() <= INLINE_CAP {
// size hint lied
return SmolStr::new_inline(&heap);
@@ -490,10 +484,7 @@ impl InlineSize {
#[derive(Clone, Debug)]
enum Repr {
- Inline {
- len: InlineSize,
- buf: [u8; INLINE_CAP],
- },
+ Inline { len: InlineSize, buf: [u8; INLINE_CAP] },
Static(&'static str),
Heap(Arc<str>),
}
@@ -521,10 +512,8 @@ impl Repr {
if len <= N_NEWLINES + N_SPACES {
let bytes = text.as_bytes();
let possible_newline_count = cmp::min(len, N_NEWLINES);
- let newlines = bytes[..possible_newline_count]
- .iter()
- .take_while(|&&b| b == b'\n')
- .count();
+ let newlines =
+ bytes[..possible_newline_count].iter().take_while(|&&b| b == b'\n').count();
let possible_space_count = len - newlines;
if possible_space_count <= N_SPACES && bytes[newlines..].iter().all(|&b| b == b' ') {
let spaces = possible_space_count;
@@ -576,16 +565,9 @@ impl Repr {
match (self, other) {
(Self::Heap(l0), Self::Heap(r0)) => Arc::ptr_eq(l0, r0),
(Self::Static(l0), Self::Static(r0)) => core::ptr::eq(l0, r0),
- (
- Self::Inline {
- len: l_len,
- buf: l_buf,
- },
- Self::Inline {
- len: r_len,
- buf: r_buf,
- },
- ) => l_len == r_len && l_buf == r_buf,
+ (Self::Inline { len: l_len, buf: l_buf }, Self::Inline { len: r_len, buf: r_buf }) => {
+ l_len == r_len && l_buf == r_buf
+ }
_ => false,
}
}
@@ -649,11 +631,7 @@ impl StrExt for str {
let len = self.len();
if len <= INLINE_CAP {
let (buf, rest) = inline_convert_while_ascii(self, u8::to_ascii_lowercase);
- from_buf_and_chars(
- buf,
- len - rest.len(),
- rest.chars().flat_map(|c| c.to_lowercase()),
- )
+ from_buf_and_chars(buf, len - rest.len(), rest.chars().flat_map(|c| c.to_lowercase()))
} else {
self.to_lowercase().into()
}
@@ -664,11 +642,7 @@ impl StrExt for str {
let len = self.len();
if len <= INLINE_CAP {
let (buf, rest) = inline_convert_while_ascii(self, u8::to_ascii_uppercase);
- from_buf_and_chars(
- buf,
- len - rest.len(),
- rest.chars().flat_map(|c| c.to_uppercase()),
- )
+ from_buf_and_chars(buf, len - rest.len(), rest.chars().flat_map(|c| c.to_uppercase()))
} else {
self.to_uppercase().into()
}
@@ -878,10 +852,7 @@ enum SmolStrBuilderRepr {
impl Default for SmolStrBuilderRepr {
#[inline]
fn default() -> Self {
- SmolStrBuilderRepr::Inline {
- buf: [0; INLINE_CAP],
- len: 0,
- }
+ SmolStrBuilderRepr::Inline { buf: [0; INLINE_CAP], len: 0 }
}
}
@@ -889,10 +860,7 @@ impl SmolStrBuilder {
/// Creates a new empty [`SmolStrBuilder`].
#[must_use]
pub const fn new() -> Self {
- Self(SmolStrBuilderRepr::Inline {
- buf: [0; INLINE_CAP],
- len: 0,
- })
+ Self(SmolStrBuilderRepr::Inline { buf: [0; INLINE_CAP], len: 0 })
}
/// Builds a [`SmolStr`] from `self`.