I was reading through the Rust docs as I want to read a binary file, and I found this example:
use std::io;
use std::io::prelude::*;
use std::fs::File;
fn main() -> io::Result<()> {
let mut f = File::open("foo.txt")?;
let mut buffer = [0; 10];
// read up to 10 bytes
let n = f.read(&mut buffer[..])?;
println!("The bytes: {:?}", &buffer[..n]);
Ok(())
}
(1) Why are there question marks before the semicolons? Also, when it says let mut buffer = [0; 10];, I presume the 10 is the array size, but what is the 0; in it? Bonus: what is the Ok(()) at the end (it doesn't have a semicolon for some reason...)
Example is here: https://doc.rust-lang.org/std/io/trait.Read.html#examples-1
The Read trait allows for reading bytes from a source.