17 lines
524 B
Rust
17 lines
524 B
Rust
use std::io::{BufRead, Cursor, Read};
|
|
|
|
fn main() {
|
|
let mut cursor = Cursor::new(b"hello world\n001");
|
|
println!("{}", cursor.position());
|
|
let mut buff = [0_u8; 5];
|
|
cursor.read_exact(&mut buff).unwrap();
|
|
println!("{:x?}", buff);
|
|
println!("{}", cursor.position());
|
|
let mut s = String::new();
|
|
cursor.read_line(&mut s).unwrap();
|
|
println!("[{}]", s);
|
|
println!("{}", cursor.position());
|
|
let mut s2 = String::new();
|
|
cursor.read_to_string(&mut s2).unwrap();
|
|
println!("[{}]", s2);
|
|
} |