From cdf7453f8fdfcb9edfa46feb474acbd7bb78147d Mon Sep 17 00:00:00 2001 From: Ryan Leckey Date: Sun, 18 Aug 2019 20:42:45 -0700 Subject: [PATCH] Run rustfmt --- examples/contacts/src/main.rs | 44 ++++++++++++++++++++--------------- src/connection.rs | 8 ++++--- src/executor.rs | 11 +++++---- 3 files changed, 37 insertions(+), 26 deletions(-) diff --git a/examples/contacts/src/main.rs b/examples/contacts/src/main.rs index 97bf4e78..546cc4af 100644 --- a/examples/contacts/src/main.rs +++ b/examples/contacts/src/main.rs @@ -9,16 +9,15 @@ use fake::{ }, Dummy, Fake, Faker, }; -use std::time::Duration; -use futures::future; -use futures::channel::oneshot::channel; -use futures::stream::TryStreamExt; -use std::io; +use futures::{channel::oneshot::channel, future, stream::TryStreamExt}; use sqlx::{ pg::{Pg, PgQuery}, - Pool, Query, Connection, + Connection, Pool, Query, +}; +use std::{ + io, + time::{Duration, Instant}, }; -use std::time::Instant; type PgPool = Pool; @@ -88,18 +87,19 @@ async fn insert(pool: &PgPool, count: usize) -> io::Result<()> { tokio::spawn(async move { sqlx::query::( - r#" + r#" INSERT INTO contacts (name, username, password, email, phone) VALUES ($1, $2, $3, $4, $5) "#, - ) - .bind(contact.name) - .bind(contact.username) - .bind(contact.password) - .bind(contact.email) - .bind(contact.phone) - .execute(&pool) - .await.unwrap(); + ) + .bind(contact.name) + .bind(contact.username) + .bind(contact.password) + .bind(contact.email) + .bind(contact.phone) + .execute(&pool) + .await + .unwrap(); tx.send(()).unwrap(); }); @@ -123,11 +123,14 @@ async fn select(pool: &PgPool, iterations: usize) -> io::Result<()> { for _ in 0..iterations { // TODO: Once we have FromRow derives we can replace this with Vec let contacts: Vec<(String, String, String, String, String)> = sqlx::query::( - r#" + r#" SELECT name, username, password, email, phone FROM contacts "#, - ).fetch(&pool).try_collect().await?; + ) + .fetch(&pool) + .try_collect() + .await?; rows = contacts.len(); } @@ -135,7 +138,10 @@ FROM contacts let elapsed = start_at.elapsed(); let per = Duration::from_nanos((elapsed.as_nanos() / (iterations as u128)) as u64); - println!("select {} rows in ~{:?} [ x{} in {:?} ]", rows, per, iterations, elapsed); + println!( + "select {} rows in ~{:?} [ x{} in {:?} ]", + rows, per, iterations, elapsed + ); Ok(()) } diff --git a/src/connection.rs b/src/connection.rs index 34775e9d..de1fd9d8 100644 --- a/src/connection.rs +++ b/src/connection.rs @@ -9,8 +9,10 @@ use futures::{ use std::{ io, ops::{Deref, DerefMut}, - sync::Arc, - sync::atomic::{AtomicBool, Ordering}, + sync::{ + atomic::{AtomicBool, Ordering}, + Arc, + }, }; pub trait RawConnection: Send { @@ -73,7 +75,7 @@ where Ok(Self(Arc::new(shared))) } - + async fn get(&self) -> ConnectionFairy { let raw = self.0.acquire().await; let conn = ConnectionFairy::new(&self.0, raw); diff --git a/src/executor.rs b/src/executor.rs index 5bfaddcb..40512c44 100644 --- a/src/executor.rs +++ b/src/executor.rs @@ -23,13 +23,16 @@ pub trait Executor: Send { T: FromRow; } -impl<'e, E> Executor for &'e E where E: Executor + Send + Sync { +impl<'e, E> Executor for &'e E +where + E: Executor + Send + Sync, +{ type Backend = E::Backend; #[inline] fn execute<'c, 'q, Q: 'q + 'c>(&'c self, query: Q) -> BoxFuture<'c, io::Result> where - Q: Query<'q, Backend = Self::Backend> + Q: Query<'q, Backend = Self::Backend>, { (*self).execute(query) } @@ -37,7 +40,7 @@ impl<'e, E> Executor for &'e E where E: Executor + Send + Sync { fn fetch<'c, 'q, A: 'c, T: 'c, Q: 'q + 'c>(&'c self, query: Q) -> BoxStream<'c, io::Result> where Q: Query<'q, Backend = Self::Backend>, - T: FromRow + Send + Unpin + T: FromRow + Send + Unpin, { (*self).fetch(query) } @@ -48,7 +51,7 @@ impl<'e, E> Executor for &'e E where E: Executor + Send + Sync { ) -> BoxFuture<'c, io::Result>> where Q: Query<'q, Backend = Self::Backend>, - T: FromRow + T: FromRow, { (*self).fetch_optional(query) }