| /// Like SmallVec but for strings. |
| pub struct SmallStr<const N: usize>(SmallVec<[u8; N]>); |
| impl<const N: usize> SmallStr<N> { |
| SmallStr(SmallVec::default()) |
| pub fn push_str(&mut self, s: &str) { |
| self.0.extend_from_slice(s.as_bytes()); |
| pub fn empty(&self) -> bool { |
| pub fn spilled(&self) -> bool { |
| pub fn as_str(&self) -> &str { |
| unsafe { std::str::from_utf8_unchecked(self.0.as_slice()) } |
| impl<const N: usize> std::ops::Deref for SmallStr<N> { |
| fn deref(&self) -> &str { |
| impl<const N: usize, A: AsRef<str>> FromIterator<A> for SmallStr<N> { |
| fn from_iter<T>(iter: T) -> Self |
| T: IntoIterator<Item = A>, |
| let mut s = SmallStr::default(); |
| impl<const N: usize, A: AsRef<str>> Extend<A> for SmallStr<N> { |
| fn extend<T>(&mut self, iter: T) |
| T: IntoIterator<Item = A>, |
| for a in iter.into_iter() { |
| self.push_str(a.as_ref()); |