This Question pertains to a pre-release version of Rust.
This younger Question is similar.char को स्ट्रिंग में कैसे परिवर्तित करें?
मैं io::println
समारोह
fn main() {
io::println('c');
}
द्वारा एक प्रतीक प्रिंट करने की कोशिश लेकिन मैं अगले त्रुटि मिली:
$ rustc pdst.rs
pdst.rs:2:16: 2:19 error: mismatched types: expected `&str` but found `char` (expected &str but found char)
pdst.rs:2 io::println('c');
^~~
error: aborting due to previous error
कैसे स्ट्रिंग के लिए चार कन्वर्ट करने के लिए?
अद्यतन
डायरेक्ट समान किरदार काम नहीं करता:
let text:str = 'c';
let text:&str = 'c';
let text:@str = 'c';
let text:~str = 'c';
यह रिटर्न:
pdst.rs:7:13: 7:16 error: bare `str` is not a type
pdst.rs:7 let text:str = 'c';
^~~
pdst.rs:7:19: 7:22 error: mismatched types: expected `~str` but found `char` (expected ~str but found char)
pdst.rs:7 let text:str = 'c';
^~~
pdst.rs:8:20: 8:23 error: mismatched types: expected `&str` but found `char` (expected &str but found char)
pdst.rs:8 let text:&str = 'c';
^~~
pdst.rs:9:20: 9:23 error: mismatched types: expected `@str` but found `char` (expected @str but found char)
pdst.rs:9 let text:@str = 'c';
^~~
pdst.rs:10:20: 10:23 error: mismatched types: expected `~str` but found `char` (expected ~str but found char)
pdst.rs:10 let text:~str = 'c';
^~~
error: aborting due to 5 previous errors
यह स्पष्ट रूप से प्रलेखित प्रतीत नहीं होता है, लेकिन यह सच है क्योंकि चार के कार्यान्वयन प्रदर्शन और प्रदर्शन कार्यान्वयन के लिए to_string की आवश्यकता होती है, लेकिन आप यह नहीं जानते कि प्रदर्शन प्रलेखन से, यह ToString विशेषता पर प्रलेखित है। जो बहुत अच्छा नहीं है। https://doc.rust-lang.org/std/string/trait.ToString.html –