expression
Read finite UTF-8 text
Decode a finite byte source as UTF-8 and report malformed text as an I/O error. Select a byte-reading method for binary data. Bound the source before reading unknown input. Tokio is an external dependency; see the proposed Cargo manifest. Expected stdout (not executed): 8 4 Common mistake: Interpreting the returned byte count as a character count.
Formal Syntax & Structure
rust syntaxrust
reader.read_to_string(&mut text).awaitWorking Example
Example Snippetrust
#[tokio::main(flavor = "current_thread")]async fn main() { use tokio::io::AsyncReadExt; let mut input = "سلام".as_bytes(); let mut text = String::new(); let n = input.read_to_string(&mut text).await.unwrap(); println!("{} {}", n, text.chars().count());}