Programming-Idioms

History of Idiom 22 > diff from v33 to v34

Edit summary for version 34 :
[Rust] Comment conciseness

Version 33

2015-12-30, 21:34:50

Version 34

2016-01-08, 13:51:09

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Idiom #22 Convert string to integer

Extract integer value i from its string representation s (in radix 10)

Code
let i = match s.parse::<i32>() {
  Ok(i) => i,
  Err(e) => {
    -1
  }
};
Code
let i = match s.parse::<i32>() {
  Ok(i) => i,
  Err(e) => {
    -1
  }
};
Comments bubble
s is parsed to 32-bits signed integer here, but you can change number type to whatever you want.
-1 is used here as a fallback value, but any error handling instructions can be used.
Comments bubble
s is parsed to 32-bits signed integer here (change number type if needed).
-1 is used here as a fallback value, but any error handling instructions can be used.