Add util to assist with Display/to_string for SmallString.
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
@@ -5,7 +5,7 @@ mod unquote;
|
|||||||
mod unquoted;
|
mod unquoted;
|
||||||
|
|
||||||
pub use self::{between::Between, split::SplitInfallible, unquote::Unquote, unquoted::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 = "";
|
pub const EMPTY: &str = "";
|
||||||
|
|
||||||
@@ -105,6 +105,18 @@ pub fn common_prefix<'a>(choice: &'a [&str]) -> &'a str {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn to_small_string<const CAP: usize, T>(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.
|
/// Parses the bytes into a string.
|
||||||
pub fn string_from_bytes(bytes: &[u8]) -> Result<String> {
|
pub fn string_from_bytes(bytes: &[u8]) -> Result<String> {
|
||||||
let str: &str = str_from_bytes(bytes)?;
|
let str: &str = str_from_bytes(bytes)?;
|
||||||
|
|||||||
Reference in New Issue
Block a user