2015-02-04 34 views

risposta

16

Vedo ora che StringimplementsWrite, in modo che possiamo semplicemente usare write!:

use std::fmt::Write; 

pub fn main() { 
    let mut a = "hello ".to_string(); 
    write!(&mut a, "{}", 5).unwrap(); 

    println!("{}", a); 
    assert_eq!("hello 5", a); 
} 

(Playground)

E is impossible for this write! call to return an Err, almeno per quanto di Rust 1.23, in modo che il unwrap non dovrebbe destare preoccupazione .

Problemi correlati