11
C'è un modo succinto per convertire un char
ad un String
a Rust diverso:Come si converte un char in una stringa?
let mut s = String::new();
s.push('c');
C'è un modo succinto per convertire un char
ad un String
a Rust diverso:Come si converte un char in una stringa?
let mut s = String::new();
s.push('c');
si utilizza il metodo to_string()
:
'c'.to_string()
Hm, che è divertente. Ho cercato l'API di Rust per 'to_string' ma non ho trovato nessun implementatore su questo metodo. Potresti pubblicare un link alla sua API. Per completezza '^ _ ^'! –
@DanielFath: stai cercando ['std :: string :: ToString :: to_string'] (http://doc.rust-lang.org/std/string/trait.ToString.html#tymethod.to_string) , che ha un impl di coperta per 'T: String', che implementa' char'. –
Oh, ecco come funziona. Pensavo che 'String' fosse un buffer come struttura, mentre in realtà è un tratto. Hmm ... –