How do I print a vector of u8 as a string?

前端 未结 4 1173
误落风尘
误落风尘 2021-02-19 01:45

Here\'s my code:

let mut altbuf: Vec = Vec::new();

// Stuff here...

match stream.read_byte() {
    Ok(d) => altbuf.push(d),
    Err(e) => { pri         


        
4条回答
  •  北恋
    北恋 (楼主)
    2021-02-19 01:50

    Use the write method from std::io:

    use std::{io, io::Write};
    
    fn main() -> io::Result<()> {
       io::stdout().write(b"March\n")?;
       Ok(())
    }
    

    It prints a slice of u8, also known as a bytestring.

    io::stdout

提交回复
热议问题