// Get the longest valid utf8 prefix as a String.
// This function never fails.
Get the longest valid utf8 prefix as a String.
This function never fails.
Get the longest valid utf8 prefix as a String . This function never fails .
fn string_from_utf8_prefix(buf: Vec<u8>) -> String
{
    String::from_utf8(buf)
        .unwrap_or_else(|e| {
            let valid_len = e.utf8_error().valid_up_to();
            let mut bytes = e.into_bytes();
            bytes.truncate(valid_len);
            String::from_utf8(bytes).expect("bug!")
        })
}
fn string_from_utf8_prefix ( buf : Vec < u8 > ) -> String { String :: from_utf8 ( buf ) . unwrap_or_else ( | e | { let valid_len = e . utf8_error ( ) . valid_up_to ( ) ; let mut bytes = e . into_bytes ( ) ; bytes . truncate ( valid_len ) ; String :: from_utf8 ( bytes ) . expect ( " " ) } ) }
Get the longest valid utf8 prefix as a String.
Get the longest valid utf8 prefix as a String .
buf
Vec<u8>