Difference between == and === in Rust
Hi everyone! I recently started learning Rust and encountered an unexpected problem when comparing values. In some languages (e.g., JavaScript), there are two comparison operators: == (with type coercion) and === (strict comparison without coercion).
I tried using === in Rust to compare strings, but the compiler gave an error:
fn main() {\n let a = String::from("hello");\n let b = String::from("hello");\n \n if a === b {\n println!("Equal");\n }\n}\n\n\nError: expected one of ".", ";", "?", "}", or an operator, found "=="
I expected === to work as a strict comparison without type coercion, but apparently there is no such operator in Rust. At the same time, bo
No answers yet.
Log in to leave an answer