These are chat archives for rust-lang/rust

25th
Jul 2015
Andy Russell
@euclio
Jul 25 2015 05:37

How do I say what type a variable is in an if let? I have

let msg: String = Decodable::decode(&mut decoder).unwrap()

but I want something like

if let Some(msg: String) = Decodable::decode(&mut decoder) {
    // ...
} else {
    // ...
}
This message was deleted
Thomas Koehler
@Bastacyclop
Jul 25 2015 10:17
I believe you can specify the type on the expression side at least
if let Some(msg) = <String as Decodable>::decode(&mut decoder) {
    // ...
} else {
    // ...
}
Erik Hedvall
@Ogeon
Jul 25 2015 10:38
String::decode(...) may also work.
Remi Rampin
@remram44
Jul 25 2015 16:02
You can always do:
let msg_opt: Option<String> = Decodable::decode(&mut decoder);
if let Some(msg) = msg_opt {
note that it returns Result and not Option though
Remi Rampin
@remram44
Jul 25 2015 19:40
Hmm, I'm not sure why there is a base64 module in rustc-serialize. Looks completely separate?