dimanche 5 avril 2015

rust - add strings and print them out


Vote count:

0




I am currently learning Rust (mostly from scratch) and now I want to add two strings together and print them out. But that is not as easy as in other languages. Here's what I've done so far (also tested with print!):



fn sayHello(id: str, msg: str) {
println!(id + msg);
}

fn main() {
sayHello("[info]", "this is rust!");
}


The error I get is a little bit weird.



$ rustc hello.rs
hello.rs:2:11: 2:19 error: expected a literal
hello.rs:2 println!(id + msg);
^~~~~~~~
note: in expansion of concat!
<std macros>:1:33: 1:58 note: expansion site
note: in expansion of format_args!
<std macros>:2:25: 2:58 note: expansion site
<std macros>:1:1: 2:62 note: in expansion of print!
<std macros>:1:23: 1:60 note: expansion site
<std macros>:1:1: 3:58 note: in expansion of println!
hello.rs:2:2: 2:21 note: expansion site
error: aborting due to previous error


How can I solve this so that [info] this is rust will be printed out?


~ J



asked 11 secs ago

Jan

1






rust - add strings and print them out

Aucun commentaire:

Enregistrer un commentaire