Rust experience sheet

Relevant Post: From Java to Rust

Answers to questions I’ve spent some time looking on the Internet to find an answer to, or which come to be relevant often.

Compare between String and &str

If we’re comparing 2 Strings and Rust shows the error expected 'String', found '&str' is because we forgot to add the .trim() part to buffer.

let mut buffer = String::new();
  .read_line(&mut buffer)
  .expect("Couldn't read user input");

if buffer.trim() == "yes" {
  // do action

Parse from &str to i32

let index_str: &str = _matches.value_of("index")
let index: i32 = index_str.parse::<i32>()