【发布时间】:2017-04-10 14:05:53
【问题描述】:
我使用 String::from("string") 来获取字符串
let dog = String::from("dog")
和
dog == String::from("dog")
返回假。即使在模式匹配中。
match dog.as_ref() {
"dog" => println!("Dog is a dog"), //no output
_ => println!("Dog is not a dog")
}
怎么了?
例子
use std::io;
fn main() {
let mut sure = String::from("");
println!("Hello, world!");
println!("Are you sure(Y/N)");
io::stdin().read_line(&mut sure).expect("Failed");
println!("sure {}", sure );
let surely = {sure == String::from("Y")};
println!("surely {} ", surely ); //this line output is "surely false"
if surely {
dog_loop("HA");
}
}
【问题讨论】:
-
无法在Rust Playground 中重现。你能创建一个minimal reproducible example吗?
-
现已编辑。我添加了示例。