use std::str::{from_utf8_unchecked, FromStr};

pub fn to_string(s: &[u8]) -> &str {
    unsafe { from_utf8_unchecked(s) }
}
pub fn to_u32(s: &str) -> u32 {
    FromStr::from_str(s).unwrap()
}

pub fn buf_to_u32(s: &[u8]) -> u32 {
    to_u32(to_string(s))
}

use std::str::{self, FromStr};

pub fn buf_to_u32(s: &[u8]) -> u32 {
    let s = str::from_utf8(s).expect("Invalid data, expected UTF-8 string");
    FromStr::from_str(s).expect("Invalid string, expected ASCII reprensation of a number")
}

Remove unsafe use of unsafe and instead panic
Remove unsafe use of unsafe and instead panic
