Fix styles

This commit is contained in:
Ivan Ukhov 2017-08-23 06:06:04 +02:00
parent ec8ecc7f04
commit b3b10acd2a
3 changed files with 27 additions and 44 deletions

View File

@ -40,11 +40,7 @@ the previous technique:
use sqlite::State; use sqlite::State;
let mut statement = connection let mut statement = connection
.prepare( .prepare("SELECT * FROM users WHERE age > ?")
"
SELECT * FROM users WHERE age > ?
",
)
.unwrap(); .unwrap();
statement.bind(1, 50).unwrap(); statement.bind(1, 50).unwrap();
@ -62,11 +58,7 @@ statement providing the concept of row and featuring all-at-once binding:
use sqlite::Value; use sqlite::Value;
let mut cursor = connection let mut cursor = connection
.prepare( .prepare("SELECT * FROM users WHERE age > ?")
"
SELECT * FROM users WHERE age > ?
",
)
.unwrap() .unwrap()
.cursor(); .cursor();

View File

@ -14,9 +14,7 @@ fn read_cursor(bencher: &mut Bencher) {
let connection = create(); let connection = create();
populate(&connection, 100); populate(&connection, 100);
let mut cursor = ok!(connection.prepare( let mut cursor = ok!(connection.prepare(
" "SELECT * FROM data WHERE a > ? AND b > ?",
SELECT * FROM data WHERE a > ? AND b > ?
",
)).cursor(); )).cursor();
bencher.iter(|| { bencher.iter(|| {
@ -33,9 +31,7 @@ fn read_statement(bencher: &mut Bencher) {
let connection = create(); let connection = create();
populate(&connection, 100); populate(&connection, 100);
let mut statement = ok!(connection.prepare( let mut statement = ok!(connection.prepare(
" "SELECT * FROM data WHERE a > ? AND b > ?",
SELECT * FROM data WHERE a > ? AND b > ?
",
)); ));
bencher.iter(|| { bencher.iter(|| {
@ -53,9 +49,7 @@ fn read_statement(bencher: &mut Bencher) {
fn write_cursor(bencher: &mut Bencher) { fn write_cursor(bencher: &mut Bencher) {
let connection = create(); let connection = create();
let mut cursor = ok!(connection.prepare( let mut cursor = ok!(connection.prepare(
" "INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)
",
)).cursor(); )).cursor();
bencher.iter(|| { bencher.iter(|| {
@ -70,9 +64,7 @@ fn write_cursor(bencher: &mut Bencher) {
fn write_statement(bencher: &mut Bencher) { fn write_statement(bencher: &mut Bencher) {
let connection = create(); let connection = create();
let mut statement = ok!(connection.prepare( let mut statement = ok!(connection.prepare(
" "INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)
",
)); ));
bencher.iter(|| { bencher.iter(|| {
@ -88,18 +80,14 @@ fn write_statement(bencher: &mut Bencher) {
fn create() -> Connection { fn create() -> Connection {
let connection = ok!(Connection::open(":memory:")); let connection = ok!(Connection::open(":memory:"));
ok!(connection.execute( ok!(connection.execute(
" "CREATE TABLE data (a INTEGER, b REAL, c REAL, d REAL)",
CREATE TABLE data (a INTEGER, b REAL, c REAL, d REAL)
",
)); ));
connection connection
} }
fn populate(connection: &Connection, count: usize) { fn populate(connection: &Connection, count: usize) {
let mut statement = ok!(connection.prepare( let mut statement = ok!(connection.prepare(
" "INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)",
INSERT INTO data (a, b, c, d) VALUES (?, ?, ?, ?)
",
)); ));
for i in 0..count { for i in 0..count {
ok!(statement.reset()); ok!(statement.reset());

View File

@ -58,11 +58,7 @@
//! # .unwrap(); //! # .unwrap();
//! //!
//! let mut statement = connection //! let mut statement = connection
//! .prepare( //! .prepare("SELECT * FROM users WHERE age > ?")
//! "
//! SELECT * FROM users WHERE age > ?
//! ",
//! )
//! .unwrap(); //! .unwrap();
//! //!
//! statement.bind(1, 50).unwrap(); //! statement.bind(1, 50).unwrap();
@ -90,11 +86,7 @@
//! # .unwrap(); //! # .unwrap();
//! //!
//! let mut cursor = connection //! let mut cursor = connection
//! .prepare( //! .prepare("SELECT * FROM users WHERE age > ?")
//! "
//! SELECT * FROM users WHERE age > ?
//! ",
//! )
//! .unwrap() //! .unwrap()
//! .cursor(); //! .cursor();
//! //!
@ -114,24 +106,35 @@ extern crate sqlite3_sys as ffi;
use std::{error, fmt}; use std::{error, fmt};
macro_rules! raise( macro_rules! raise(
($message:expr) => (return Err(::Error { code: None, message: Some($message.to_string()) })); ($message:expr) => (
return Err(::Error {
code: None,
message: Some($message.to_string()),
})
);
); );
macro_rules! error( macro_rules! error(
($connection:expr, $code:expr) => (match ::last_error($connection) { ($connection:expr, $code:expr) => (match ::last_error($connection) {
Some(error) => return Err(error), Some(error) => return Err(error),
_ => return Err(::Error { code: Some($code as isize), message: None }), _ => return Err(::Error {
code: Some($code as isize),
message: None,
}),
}); });
); );
macro_rules! ok( macro_rules! ok(
($connection:expr, $result:expr) => (match $result { ($connection:expr, $result:expr) => (match $result {
::ffi::SQLITE_OK => {}, ::ffi::SQLITE_OK => {}
code => error!($connection, code), code => error!($connection, code),
}); });
($result:expr) => (match $result { ($result:expr) => (match $result {
::ffi::SQLITE_OK => {}, ::ffi::SQLITE_OK => {}
code => return Err(::Error { code: Some(code as isize), message: None }), code => return Err(::Error {
code: Some(code as isize),
message: None,
}),
}); });
); );
@ -151,7 +154,7 @@ macro_rules! path_to_cstr(
Some(path) => match ::std::ffi::CString::new(path) { Some(path) => match ::std::ffi::CString::new(path) {
Ok(string) => string, Ok(string) => string,
_ => raise!("failed to process a path"), _ => raise!("failed to process a path"),
}, }
_ => raise!("failed to process a path"), _ => raise!("failed to process a path"),
}); });
); );