diff --git a/crates/polars-utils/src/pl_str.rs b/crates/polars-utils/src/pl_str.rs index 7acaa70fd1f9..72beb122b233 100644 --- a/crates/polars-utils/src/pl_str.rs +++ b/crates/polars-utils/src/pl_str.rs @@ -3,9 +3,9 @@ macro_rules! format_pl_smallstr { ($($arg:tt)*) => {{ use std::fmt::Write; - let mut string = String::new(); + let mut string = PlSmallStr::EMPTY; write!(string, $($arg)*).unwrap(); - PlSmallStr::from_string(string) + string }} } @@ -125,7 +125,70 @@ impl From<&String> for PlSmallStr { } } -/// FromIterator impls (TODO) +impl From for PlSmallStr { + #[inline(always)] + fn from(value: Inner) -> Self { + Self(value) + } +} + +/// FromIterator impls + +impl FromIterator for PlSmallStr { + #[inline(always)] + fn from_iter>(iter: T) -> Self { + Self(Inner::from_iter(iter.into_iter().map(|x| x.0))) + } +} + +impl<'a> FromIterator<&'a PlSmallStr> for PlSmallStr { + #[inline(always)] + fn from_iter>(iter: T) -> Self { + Self(Inner::from_iter(iter.into_iter().map(|x| x.as_str()))) + } +} + +impl FromIterator for PlSmallStr { + #[inline(always)] + fn from_iter>(iter: I) -> PlSmallStr { + Self(Inner::from_iter(iter)) + } +} + +impl<'a> FromIterator<&'a char> for PlSmallStr { + #[inline(always)] + fn from_iter>(iter: I) -> PlSmallStr { + Self(Inner::from_iter(iter)) + } +} + +impl<'a> FromIterator<&'a str> for PlSmallStr { + #[inline(always)] + fn from_iter>(iter: I) -> PlSmallStr { + Self(Inner::from_iter(iter)) + } +} + +impl FromIterator for PlSmallStr { + #[inline(always)] + fn from_iter>(iter: I) -> PlSmallStr { + Self(Inner::from_iter(iter)) + } +} + +impl FromIterator> for PlSmallStr { + #[inline(always)] + fn from_iter>>(iter: I) -> PlSmallStr { + Self(Inner::from_iter(iter)) + } +} + +impl<'a> FromIterator> for PlSmallStr { + #[inline(always)] + fn from_iter>>(iter: I) -> PlSmallStr { + Self(Inner::from_iter(iter)) + } +} /// PartialEq impls @@ -153,6 +216,25 @@ impl PartialEq for String { } } +/// Write + +impl core::fmt::Write for PlSmallStr { + #[inline(always)] + fn write_char(&mut self, c: char) -> std::fmt::Result { + self.0.write_char(c) + } + + #[inline(always)] + fn write_fmt(&mut self, args: std::fmt::Arguments<'_>) -> std::fmt::Result { + self.0.write_fmt(args) + } + + #[inline(always)] + fn write_str(&mut self, s: &str) -> std::fmt::Result { + self.0.write_str(s) + } +} + /// Debug, Display impl core::fmt::Debug for PlSmallStr {