Closed
Description
Here is the code:
#[derive(Debug)]
enum Message {
Quit,
ChangeColor(i32, i32, i32),
Move { x: i32, y: i32 },
Write(String),
}
enum BoardGameTurn {
Move { squares: i32 },
Pass,
}
fn main() {
let x: Message = Message::Move { x: 3, y: 4 };
// let v = "hello world".split_whitespace();
// let v: Vec<String> = "hello world".split_whitespace().map(|x| x.to_string()).collect();
let v = "hello world".split_whitespace().map(|x| x.to_string()).collect();
// let v = vec!["Hello".to_string(), "World".to_string()];
fn write_str(s: &str) -> Message {
Message::Write(s.to_string())
}
let v1: Vec<Message> = v.into_iter().map(Message::Write).collect();
let y: BoardGameTurn = BoardGameTurn::Move { squares: 1 };
for i in v1 {
println!("{:?}", i);
}
}
Compiler says:
cargo run
Compiling rustcallc v0.1.0 (file:///Users/kaiyin/Documents/workspace-eclipse-neon/rustcallc)
error: the type of this value must be known in this context
--> src/main.rs:21:28
|
21 | let v1: Vec<Message> = v.into_iter().map(Message::Write).collect();
| ^^^^^^^^^^^^^
error: aborting due to previous error
error: Could not compile `rustcallc`.
The actual error is in this line:
let v = "hello world".split_whitespace().map(|x| x.to_string()).collect();
which should have specified the type of v
.
The compiler could have been more precise about the error.