fn buf_to_str(buf: Vec<u8>) -> Result<String, Utf8Error> {
    // This should never be possible - writer is given a 4mb buffer
    // and should be writing a null terminated string. So if the last
    // byte is not NULL, something has gone horrifically wrong.
    if *buf.last().unwrap() != b'\0' {
        unreachable!()
    }

    unsafe {
        CStr::from_ptr(buf.as_ptr() as *const _)
            .to_str()
            .map(|s| s.trim_end().to_owned())
    }
}
/// Takes a buffer that should contain a UTF8 string and converts it
/// into a Rust string. Panics if the buffer is not null terminated,
/// as this would represent utter chaos.
Takes a buffer that should contain a UTF8 string and converts it
into a Rust string. Panics if the buffer is not null terminated,
as this would represent utter chaos.
Takes a buffer that should contain a UTF8 string and converts it into a Rust string . Panics if the buffer is not null terminated as this would represent utter chaos .
fn buf_to_str(buf: Vec<u8>) -> Result<String, Utf8Error> {
    // This should never be possible - writer is given a 4mb buffer
    // and should be writing a null terminated string. So if the last
    // byte is not NULL, something has gone horrifically wrong.
    if *buf.last().unwrap() != b'\0' {
        unreachable!()
    }
    unsafe {
        CStr::from_ptr(buf.as_ptr() as *const _)
            .to_str()
            .map(|s| s.trim_end().to_owned())
    }
}
fn buf_to_str ( buf : Vec < u8 > ) -> Result < String , Utf8Error > { // This should never be possible - writer is given a 4mb buffer // and should be writing a null terminated string. So if the last // byte is not NULL, something has gone horrifically wrong. if * buf . last ( ) . unwrap ( ) != b'\0' { unreachable ! ( ) } unsafe { CStr :: from_ptr ( buf . as_ptr ( ) as * const _ ) . to_str ( ) . map ( | s | s . trim_end ( ) . to_owned ( ) ) } }
Takes a buffer that should contain a UTF8 string and converts it
into a Rust string.
Takes a buffer that should contain a UTF8 string and converts it into a Rust string .
buf
Vec<u8>
buf
Vec<u8>