I'm digging into Rust, specifically into gracefully handling errors, but I'm having a little trouble with type inference.
extern crate mysql;
use mysql as my;
fn main() {
my_test();
}
fn my_test() -> Result<(), my::Error> {
let pool = try!(my::Pool::new(""));
let res = try!(pool.prep_exec("select 1 as count", ()));
for rows in res {
let row: my::Row = try!(rows);
match row.take("count") {
None => (),
Some(i) => println!("{:?}", i),
};
}
Ok(())
}
which leads to
src/bin/main.rs:86:12: 86:13 error: unable to infer enough type information about
_
; type annotations or generic parameter binding required [E0282]
Unfortunately the docs in that crate use unwrap
a lot, which does not help me. In Haskell, I would do something like println!("{:?}", i :: i32)
, but I can't figure out how to do it in Rust. I've tried various ways to cast row.take
, but I've haven't had any luck. I'd love to see a variety of ways in which I could have structured this code, if there is a more idiomatic way of going about it.
println!
, which takes a wide range of values. If you were to use thei
value in some context that constrained the type (like by passing it to a function), then the type could be inferred. – Shepmaster