Remove unwrap from examples

This commit is contained in:
gwenn
2019-02-09 07:16:05 +01:00
parent 7c5bfb7cc3
commit d70286e98a
4 changed files with 33 additions and 39 deletions

View File

@@ -11,7 +11,7 @@ an interface similar to [rust-postgres](https://github.com/sfackler/rust-postgre
```rust
use rusqlite::types::ToSql;
use rusqlite::{Connection, NO_PARAMS};
use rusqlite::{Connection, Result, NO_PARAMS};
use time::Timespec;
#[derive(Debug)]
@@ -22,8 +22,8 @@ struct Person {
data: Option<Vec<u8>>,
}
fn main() {
let conn = Connection::open_in_memory().unwrap();
fn main() -> Result<()> {
let conn = Connection::open_in_memory()?;
conn.execute(
"CREATE TABLE person (
@@ -33,7 +33,7 @@ fn main() {
data BLOB
)",
NO_PARAMS,
).unwrap();
)?;
let me = Person {
id: 0,
name: "Steven".to_string(),
@@ -44,22 +44,22 @@ fn main() {
"INSERT INTO person (name, time_created, data)
VALUES (?1, ?2, ?3)",
&[&me.name as &ToSql, &me.time_created, &me.data],
).unwrap();
)?;
let mut stmt = conn
.prepare("SELECT id, name, time_created, data FROM person")
.unwrap();
.prepare("SELECT id, name, time_created, data FROM person")?;
let person_iter = stmt
.query_map(NO_PARAMS, |row| Person {
id: row.get(0),
name: row.get(1),
time_created: row.get(2),
data: row.get(3),
}).unwrap();
})?;
for person in person_iter {
println!("Found person {:?}", person.unwrap());
}
Ok(())
}
```