MSSQL ODBC to Rust Structure?

First of all, I'm new to Rust, but creating a simple application allows me to learn by doing. I'm sorry if this is a simple question, but I'm stuck.

I have Rust 1.37 and odbc 0.14.0, I can connect to the Microsoft SQL Server and I can run simple queries, great! But, I can't figure out how to "cast" the cursor to a structure into an array.

Any ideas? Thank you


I haven't used odbc myself, but assuming you've got a Cursor, it looks like you'll need to manually extract the values from it into a structure. Something like:

// cursor: odbc::Cursor
let id = cursor.get_data<u32>(0)?;  // first column
let name = cursor.get_data<String>(1)?;  // second column
let res = MyStruct { id, name };

Perfect answer, this pointed me in the correct direction. With a little more digging I came up with the following:

while let Some(mut cursor) = stmt.fetch()? {
                    match cursor.get_data::<&str>(1)?{
                        Some(val)=> ( index = val.parse().unwrap()),
                        None => ( index = 0),
                    match cursor.get_data::<&str>(2)?{
                        Some(val)=> ( state = val.to_string()),
                        None => ( state = String::new()),
                    match cursor.get_data::<&str>(3)?{
                        Some(val)=> ( city = val.to_string()),
                        None => ( city = String::new()),

                vec.push(ZIP { index: index, state: state, city: city });

I note that the cursor index starts at 1 not 0 as I would expect, and I would assume this block can be cleaned up with a little effort on my part.

But thank you for your kind help in my learning process.