From 2f0716b6cfbe38e050531c5b3e3a8defa9286f9a Mon Sep 17 00:00:00 2001 From: Orion Kindel Date: Fri, 7 Jul 2023 12:32:36 -0500 Subject: [PATCH] fix: fmt + update pg --- postgres | 2 +- src/hashed_text.rs | 48 +++++++++++++++++++++++++--------------------- src/postgres.rs | 24 +++++++++++------------ src/user.rs | 3 ++- 4 files changed, 41 insertions(+), 36 deletions(-) diff --git a/postgres b/postgres index 6c6a266..c7abba1 160000 --- a/postgres +++ b/postgres @@ -1 +1 @@ -Subproject commit 6c6a266c1449a5d754d1b3771df58ad5dbbf7b02 +Subproject commit c7abba1e135e0be13cc857c4b8f9e86d8fc51b45 diff --git a/src/hashed_text.rs b/src/hashed_text.rs index 49b8de7..fef8091 100644 --- a/src/hashed_text.rs +++ b/src/hashed_text.rs @@ -31,40 +31,44 @@ impl HashedTextExt for HashedTextExtImpl where Db: Postgres #[cfg(test)] mod test { - use std::{any::Any, panic::AssertUnwindSafe}; + use std::any::Any; + use std::panic::AssertUnwindSafe; -use postgres::types::{Type, ToSql, private::BytesMut, FromSql}; + use postgres::types::private::BytesMut; + use postgres::types::{FromSql, ToSql, Type}; -use crate::{postgres::{test::{Client, Row}, PostgresImpl, Postgres}}; - -use super::{HashedTextExtImpl, HashedTextExt, HashedText}; + use super::{HashedText, HashedTextExt, HashedTextExtImpl}; + use crate::postgres::test::{Client, Row}; + use crate::postgres::{Postgres, PostgresImpl}; #[test] fn hashed_text_matches_fn_call() { - let client = || Client { - query_one: Box::new(|_, q, ps| { - assert_eq!(q.unwrap_str(), "select public.hashed_text_matches($1, public.hashed_text_of_string($2))"); + let client = || Client { query_one: Box::new(|_, q, ps| { + assert_eq!(q.unwrap_str(), "select public.hashed_text_matches($1, public.hashed_text_of_string($2))"); - let mut p0 = BytesMut::with_capacity(32); - let mut p1 = BytesMut::with_capacity(32); + let mut p0 = BytesMut::with_capacity(32); + let mut p1 = BytesMut::with_capacity(32); - ps[0].to_sql(&Type::TEXT, &mut p0).unwrap(); - ps[1].to_sql(&Type::TEXT, &mut p1).unwrap(); + ps[0].to_sql(&Type::TEXT, &mut p0).unwrap(); + ps[1].to_sql(&Type::TEXT, &mut p1).unwrap(); - let p0 = <&str as FromSql>::from_sql(&Type::TEXT, &p0).unwrap(); - let p1 = <&str as FromSql>::from_sql(&Type::TEXT, &p1).unwrap(); + let p0 = <&str as FromSql>::from_sql(&Type::TEXT, &p0).unwrap(); + let p1 = <&str as FromSql>::from_sql(&Type::TEXT, &p1).unwrap(); - assert_eq!(p1, "XXX"); + assert_eq!(p1, "XXX"); - Ok(Row::new(vec![("", Type::BOOL)]).value(Type::BOOL, p0 == "foo")) - }), - ..Client::default() - }; + Ok(Row::new(vec![("", Type::BOOL)]).value(Type::BOOL, p0 == "foo")) + }), + ..Client::default() }; let pg = PostgresImpl::>::try_new(|| Ok(client()), 1).unwrap(); - let htext = HashedTextExtImpl(unsafe {std::mem::transmute::<_, &'static PostgresImpl>>(&pg)}); + let htext = HashedTextExtImpl(unsafe { + std::mem::transmute::<_, &'static PostgresImpl>>(&pg) + }); - assert!(htext.matches(&HashedText(String::from("XXX")), "foo").unwrap()); - assert!(!htext.matches(&HashedText(String::from("XXX")), "foob").unwrap()); + assert!(htext.matches(&HashedText(String::from("XXX")), "foo") + .unwrap()); + assert!(!htext.matches(&HashedText(String::from("XXX")), "foob") + .unwrap()); } } diff --git a/src/postgres.rs b/src/postgres.rs index b2cae53..6350e62 100644 --- a/src/postgres.rs +++ b/src/postgres.rs @@ -148,7 +148,7 @@ pub mod test { Transaction}; use postgres::types::private::BytesMut; use postgres::types::{FromSql, ToSql, Type}; - use postgres::{Column, GenericRow, GenericClient}; + use postgres::{Column, GenericClient, GenericRow}; use super::{Postgres, PostgresImpl}; @@ -160,14 +160,16 @@ pub mod test { impl Row { pub fn new(cols: Vec<(&'static str, Type)>) -> Self { - Self { - columns: cols.into_iter().map(|(name, ty)| Column::new(name.to_string(), ty)).collect(), - values: vec![], - __phantom: PhantomData, - } + Self { columns: cols.into_iter() + .map(|(name, ty)| Column::new(name.to_string(), ty)) + .collect(), + values: vec![], + __phantom: PhantomData } } - pub fn value(mut self, ty: Type, val: V) -> Self where V: ToSql { + pub fn value(mut self, ty: Type, val: V) -> Self + where V: ToSql + { let mut bs = BytesMut::with_capacity(128); val.to_sql(&ty, &mut bs).unwrap(); self.values.push(bs); @@ -175,7 +177,8 @@ pub mod test { } } - impl GenericRow for Row where E: core::fmt::Debug { + impl GenericRow for Row where E: core::fmt::Debug + { type Error = E; fn columns(&self) -> &[Column] { @@ -292,10 +295,7 @@ pub mod test { res } - fn query_raw(&mut self, - _: &T, - _: I) - -> Result, Self::Error> + fn query_raw(&mut self, _: &T, _: I) -> Result, Self::Error> where T: ?Sized + postgres::ToStatement, P: postgres::types::BorrowToSql, I: IntoIterator, diff --git a/src/user.rs b/src/user.rs index e85d83e..0a1ed79 100644 --- a/src/user.rs +++ b/src/user.rs @@ -1,5 +1,6 @@ +use crate::hashed_text::HashedText; use crate::repo::Repo; -use crate::{Email, hashed_text::HashedText}; +use crate::Email; #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)] pub struct UserId(String);