diff --git a/src/core/utils/string.rs b/src/core/utils/string.rs index ca2e62b5..0873b2d5 100644 --- a/src/core/utils/string.rs +++ b/src/core/utils/string.rs @@ -5,7 +5,7 @@ mod unquote; mod unquoted; pub use self::{between::Between, split::SplitInfallible, unquote::Unquote, unquoted::Unquoted}; -use crate::{Result, utils::exchange}; +use crate::{Result, smallstr::SmallString, utils::exchange}; pub const EMPTY: &str = ""; @@ -105,6 +105,18 @@ pub fn common_prefix<'a>(choice: &'a [&str]) -> &'a str { }) } +pub fn to_small_string(t: T) -> SmallString<[u8; CAP]> +where + T: std::fmt::Display, +{ + use std::fmt::Write; + + let mut ret = SmallString::<[u8; CAP]>::new(); + write!(&mut ret, "{t}").expect("Failed to Display type in SmallString"); + + ret +} + /// Parses the bytes into a string. pub fn string_from_bytes(bytes: &[u8]) -> Result { let str: &str = str_from_bytes(bytes)?;