Skip to content

Commit 5aa9d50

Browse files
committed
chore: run cargo fmt
1 parent 6599f1c commit 5aa9d50

File tree

7 files changed

+43
-36
lines changed

7 files changed

+43
-36
lines changed

sqlx-postgres/src/arguments.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ impl DerefMut for PgArgumentBuffer {
274274
}
275275

276276
pub(crate) fn value_size_int4_checked(size: usize) -> Result<i32, String> {
277-
i32::try_from(size)
278-
.map_err(|_| format!("value size would overflow in the binary protocol encoding: {size} > {}", i32::MAX))
277+
i32::try_from(size).map_err(|_| {
278+
format!(
279+
"value size would overflow in the binary protocol encoding: {size} > {}",
280+
i32::MAX
281+
)
282+
})
279283
}

sqlx-postgres/src/connection/describe.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::error::Error;
22
use crate::ext::ustr::UStr;
33
use crate::message::{ParameterDescription, RowDescription};
44
use crate::query_as::query_as;
5-
use crate::query_scalar::{query_scalar};
5+
use crate::query_scalar::query_scalar;
66
use crate::statement::PgStatementMetadata;
77
use crate::type_info::{PgArrayOf, PgCustomType, PgType, PgTypeKind};
88
use crate::types::Json;
@@ -11,8 +11,8 @@ use crate::HashMap;
1111
use crate::{PgColumn, PgConnection, PgTypeInfo};
1212
use futures_core::future::BoxFuture;
1313
use smallvec::SmallVec;
14-
use std::sync::Arc;
1514
use sqlx_core::query_builder::QueryBuilder;
15+
use std::sync::Arc;
1616

1717
/// Describes the type of the `pg_type.typtype` column
1818
///
@@ -426,7 +426,7 @@ WHERE rngtypid = $1
426426
if meta.columns.len() * 3 > 65535 {
427427
tracing::debug!(
428428
?stmt_id,
429-
num_columns=meta.columns.len(),
429+
num_columns = meta.columns.len(),
430430
"number of columns in query is too large to pull nullability for"
431431
);
432432
}
@@ -436,19 +436,18 @@ WHERE rngtypid = $1
436436
// This will include columns that don't have a `relation_id` (are not from a table);
437437
// assuming those are a minority of columns, it's less code to _not_ work around it
438438
// and just let Postgres return `NULL`.
439-
let mut nullable_query = QueryBuilder::new(
440-
"SELECT NOT pg_attribute.attnotnull FROM ( "
441-
);
442-
443-
nullable_query.push_values(
444-
meta.columns.iter().zip(0i32..),
445-
|mut tuple, (column, i)| {
446-
// ({i}::int4, {column.relation_id}::int4, {column.relation_attribute_no}::int2)
447-
tuple.push_bind(i).push_unseparated("::int4");
448-
tuple.push_bind(column.relation_id).push_unseparated("::int4");
449-
tuple.push_bind(column.relation_attribute_no).push_bind_unseparated("::int2");
450-
},
451-
);
439+
let mut nullable_query = QueryBuilder::new("SELECT NOT pg_attribute.attnotnull FROM ( ");
440+
441+
nullable_query.push_values(meta.columns.iter().zip(0i32..), |mut tuple, (column, i)| {
442+
// ({i}::int4, {column.relation_id}::int4, {column.relation_attribute_no}::int2)
443+
tuple.push_bind(i).push_unseparated("::int4");
444+
tuple
445+
.push_bind(column.relation_id)
446+
.push_unseparated("::int4");
447+
tuple
448+
.push_bind(column.relation_attribute_no)
449+
.push_bind_unseparated("::int2");
450+
});
452451

453452
nullable_query.push(
454453
") as col(idx, table_id, col_idx) \

sqlx-postgres/src/types/bit_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use crate::arguments::value_size_int4_checked;
12
use crate::{
23
decode::Decode,
34
encode::{Encode, IsNull},
@@ -8,7 +9,6 @@ use crate::{
89
use bit_vec::BitVec;
910
use sqlx_core::bytes::Buf;
1011
use std::{io, mem};
11-
use crate::arguments::value_size_int4_checked;
1212

1313
impl Type<Postgres> for BitVec {
1414
fn type_info() -> PgTypeInfo {

sqlx-postgres/src/types/chrono/date.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ impl Encode<'_, Postgres> for NaiveDate {
2626
let days: i32 = (*self - postgres_epoch_date())
2727
.num_days()
2828
.try_into()
29-
.map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres DATE"))?;
29+
.map_err(|_| {
30+
format!("value {self:?} would overflow binary encoding for Postgres DATE")
31+
})?;
3032

3133
Encode::<Postgres>::encode(days, buf)
3234
}

sqlx-postgres/src/types/rust_decimal.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -193,15 +193,9 @@ mod tests {
193193
fn zero() {
194194
let zero: Decimal = "0".parse().unwrap();
195195

196-
assert_eq!(
197-
PgNumeric::from(&zero),
198-
PgNumeric::ZERO,
199-
);
196+
assert_eq!(PgNumeric::from(&zero), PgNumeric::ZERO,);
200197

201-
assert_eq!(
202-
Decimal::try_from(&PgNumeric::ZERO).unwrap(),
203-
Decimal::ZERO
204-
);
198+
assert_eq!(Decimal::try_from(&PgNumeric::ZERO).unwrap(), Decimal::ZERO);
205199
}
206200

207201
#[test]
@@ -384,7 +378,10 @@ mod tests {
384378
let actual_decimal = Decimal::try_from(expected_numeric).unwrap();
385379
assert_eq!(actual_decimal, Decimal::MAX);
386380
// Value split by 10,000's to match the expected digits[]
387-
assert_eq!(actual_decimal.mantissa(), 7_9228_1625_1426_4337_5935_4395_0335);
381+
assert_eq!(
382+
actual_decimal.mantissa(),
383+
7_9228_1625_1426_4337_5935_4395_0335
384+
);
388385
assert_eq!(actual_decimal.scale(), 0);
389386
}
390387

@@ -406,7 +403,10 @@ mod tests {
406403

407404
let actual_decimal = Decimal::try_from(expected_numeric).unwrap();
408405
assert_eq!(actual_decimal, max_value_max_scale);
409-
assert_eq!(actual_decimal.mantissa(), 79_228_162_514_264_337_593_543_950_335);
406+
assert_eq!(
407+
actual_decimal.mantissa(),
408+
79_228_162_514_264_337_593_543_950_335
409+
);
410410
assert_eq!(actual_decimal.scale(), 28);
411411
}
412412

sqlx-postgres/src/types/time/date.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ impl PgHasArrayType for Date {
2323
impl Encode<'_, Postgres> for Date {
2424
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result<IsNull, BoxDynError> {
2525
// DATE is encoded as number of days since epoch (2000-01-01)
26-
let days: i32 = (*self - PG_EPOCH)
27-
.whole_days()
28-
.try_into()
29-
.map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres DATE"))?;
26+
let days: i32 = (*self - PG_EPOCH).whole_days().try_into().map_err(|_| {
27+
format!("value {self:?} would overflow binary encoding for Postgres DATE")
28+
})?;
3029
Encode::<Postgres>::encode(days, buf)
3130
}
3231

sqlx-postgres/src/types/time/datetime.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,12 @@ impl PgHasArrayType for OffsetDateTime {
3737
impl Encode<'_, Postgres> for PrimitiveDateTime {
3838
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> Result<IsNull, BoxDynError> {
3939
// TIMESTAMP is encoded as the microseconds since the epoch
40-
let micros: i64 = (*self - PG_EPOCH.midnight()).whole_microseconds()
40+
let micros: i64 = (*self - PG_EPOCH.midnight())
41+
.whole_microseconds()
4142
.try_into()
42-
.map_err(|_| format!("value {self:?} would overflow binary encoding for Postgres TIME"))?;
43+
.map_err(|_| {
44+
format!("value {self:?} would overflow binary encoding for Postgres TIME")
45+
})?;
4346
Encode::<Postgres>::encode(micros, buf)
4447
}
4548

0 commit comments

Comments
 (0)