On Sat, May 18, 2013 at 11:46 AM, Renato Lenzi <[email protected]> wrote:
> I don't understand why this code is bad:
>
>    let n1 = int::from_str(line);
>    if n1 == 0
>
> compiler complains:
>
> 00003.rs:7:12: 7:13 error: mismatched types: expected
> `core::option::Option<int>
> ` but found `<VI0>` (expected enum core::option::Option but found integral
> varia
> ble)
> 00003.rs:7    if n1 == 0
>

from_str returns an Option<int>, see
http://static.rust-lang.org/doc/core/option.html. If you don't care
about the case where line is not a valid integer, you can use the
unwrap method. Else, use:

```
match int::from_str(line) {
    Some(x) => n1 = x,
    None => { /* handle error... */}
}
if n1 == 0 {
...
```
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to