/// Converts a string of bytes to an ASCII string if all characters are within the printable ASCII
/// range. If a null byte is encounted, the string terminates at that point.
Converts a string of bytes to an ASCII string if all characters are within the printable ASCII
range. If a null byte is encounted, the string terminates at that point.
Converts a string of bytes to an ASCII string if all characters are within the printable ASCII range . If a null byte is encounted the string terminates at that point .
fn printable_ascii_to_string(bytes: &[u8]) -> Option<String> {
    let mut result = String::with_capacity(bytes.len());
    for c in bytes {
        match c {
            0x00        => break,
            0x20..=0x7e => result.push(char::from(*c)),
            _           => return None,
        }
    }
    Some(result)
}
fn printable_ascii_to_string ( bytes : & [ u8 ] ) -> Option < String > { let mut result = String :: with_capacity ( bytes . len ( ) ) ; for c in bytes { match c { 0x00 => break , 0x20 ..= 0x7e => result . push ( char :: from ( * c ) ) , _ => return None , } } Some ( result ) }
Converts a string of bytes to an ASCII string if all characters are within the printable ASCII
range.
Converts a string of bytes to an ASCII string if all characters are within the printable ASCII range .
bytes
&[u8]