diff --git a/src/utils/mod.rs b/src/utils/mod.rs index f1411016..ea694a03 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -67,8 +67,11 @@ pub fn u64_from_bytes(bytes: &[u8]) -> Result Result { - String::from_utf8(bytes.to_vec()) +/// +/// If `&str` is enough please use [str::from_utf8] to avoid unnecessary +/// allocation. +pub fn string_from_bytes(bytes: &[u8]) -> Result { + str::from_utf8(bytes).map(ToOwned::to_owned) } pub fn random_string(length: usize) -> String {