mirror of
https://github.com/shiroyashik/sculptor.git
synced 2025-12-06 13:01:12 +03:00
use tracing instead, revert this string converter function
This commit is contained in:
parent
d4f0aa96c3
commit
6d26330bd8
3 changed files with 33 additions and 1 deletions
20
src/utils.rs
20
src/utils.rs
|
|
@ -16,9 +16,27 @@ pub fn rand() -> [u8; 50] {
|
|||
nums
|
||||
}
|
||||
//? What is this guy doing
|
||||
#[tracing::instrument]
|
||||
pub fn bytes_into_string(code: &[u8]) -> String {
|
||||
// This *might* be the correct way to do it.
|
||||
|
||||
// code.iter().map(|byte| format!("{:02x}", byte)).collect::<String>() // ????? Why do you need this? Why not just String::from_utf8()??
|
||||
String::from_utf8_lossy(code).to_string()
|
||||
// So we need to turn each byte into a string with a 2-digit hexadecimal representation apparently...
|
||||
|
||||
// hex::encode_to_slice(input, output)
|
||||
|
||||
let res = code.iter().fold(String::new(), |mut acc, byte| {
|
||||
acc.push_str(&format!("{:02x}", byte));
|
||||
acc
|
||||
}); // This is the same as the above, but with a fold instead of a map
|
||||
|
||||
|
||||
// Can we do this with hex::encode instead?
|
||||
|
||||
|
||||
res
|
||||
|
||||
// String::from_utf8_lossy(code).to_string() // Tried this, causes corrupted string
|
||||
}
|
||||
// Конец кор функций
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue