Skip to content

Commit

Permalink
clippy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Weakky committed May 29, 2024
1 parent fe0cfc3 commit 5595382
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 22 deletions.
6 changes: 6 additions & 0 deletions src/sql_read_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ macro_rules! bytes_reader {

pub(crate) trait SqlReadBytes: AsyncRead + Unpin {
// Pretty-print current wire content.
#[allow(dead_code)]
fn debug_buffer(&self);

// The client state.
Expand All @@ -165,6 +166,7 @@ pub(crate) trait SqlReadBytes: AsyncRead + Unpin {
fn context_mut(&mut self) -> &mut Context;

// Read a single i8 value.
#[allow(dead_code)]
fn read_i8(&mut self) -> ReadI8<&mut Self>
where
Self: Unpin,
Expand All @@ -189,6 +191,7 @@ pub(crate) trait SqlReadBytes: AsyncRead + Unpin {
}

// Read a single big-endian f32 value.
#[allow(dead_code)]
fn read_f32(&mut self) -> ReadF32<&mut Self>
where
Self: Unpin,
Expand All @@ -197,6 +200,7 @@ pub(crate) trait SqlReadBytes: AsyncRead + Unpin {
}

// Read a single big-endian f64 value.
#[allow(dead_code)]
fn read_f64(&mut self) -> ReadF64<&mut Self>
where
Self: Unpin,
Expand Down Expand Up @@ -245,6 +249,7 @@ pub(crate) trait SqlReadBytes: AsyncRead + Unpin {
}

// Read a single u128 value.
#[allow(dead_code)]
fn read_u128_le(&mut self) -> ReadU128Le<&mut Self>
where
Self: Unpin,
Expand Down Expand Up @@ -277,6 +282,7 @@ pub(crate) trait SqlReadBytes: AsyncRead + Unpin {
}

// Read a single i128 value.
#[allow(dead_code)]
fn read_i128_le(&mut self) -> ReadI128Le<&mut Self>
where
Self: Unpin,
Expand Down
12 changes: 6 additions & 6 deletions src/tds/time/chrono.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ from_sql!(
let offset = chrono::Duration::minutes(dto.offset as i64);
let naive = NaiveDateTime::new(date, time).sub(offset);

chrono::DateTime::from_utc(naive, Utc)
chrono::DateTime::from_naive_utc_and_offset(naive, Utc)
});
chrono::DateTime<FixedOffset>: ColumnData::DateTimeOffset(ref dto) => dto.map(|dto| {
let date = from_days(dto.datetime2.date.days() as i64, 1);
Expand All @@ -91,7 +91,7 @@ from_sql!(
let offset = FixedOffset::east_opt((dto.offset as i32) * 60).unwrap();
let naive = NaiveDateTime::new(date, time);

chrono::DateTime::from_utc(naive, offset)
chrono::DateTime::from_naive_utc_and_offset(naive, offset)
})
);

Expand All @@ -118,7 +118,7 @@ to_sql!(self_,

DateTime2::new(date, time)
});
chrono::DateTime<Utc>: (ColumnData::DateTimeOffset, {
chrono::DateTime<Utc>: (ColumnData::DateTime2, {
use chrono::Timelike;

let naive = self_.naive_utc();
Expand All @@ -128,7 +128,7 @@ to_sql!(self_,
let date = Date::new(to_days(naive.date(), 1) as u32);
let time = Time {increments: nanos / 100, scale: 7};

DateTimeOffset::new(DateTime2::new(date, time), 0)
DateTime2::new(date, time)
});
chrono::DateTime<FixedOffset>: (ColumnData::DateTimeOffset, {
use chrono::Timelike;
Expand Down Expand Up @@ -170,7 +170,7 @@ into_sql!(self_,

DateTime2::new(date, time)
});
chrono::DateTime<Utc>: (ColumnData::DateTimeOffset, {
chrono::DateTime<Utc>: (ColumnData::DateTime2, {
use chrono::Timelike;

let naive = self_.naive_utc();
Expand All @@ -180,7 +180,7 @@ into_sql!(self_,
let date = Date::new(to_days(naive.date(), 1) as u32);
let time = Time {increments: nanos / 100, scale: 7};

DateTimeOffset::new(DateTime2::new(date, time), 0)
DateTime2::new(date, time)
});
chrono::DateTime<FixedOffset>: (ColumnData::DateTimeOffset, {
use chrono::Timelike;
Expand Down
6 changes: 3 additions & 3 deletions src/tds/xml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,9 @@ impl XmlData {
}
}

impl ToString for XmlData {
fn to_string(&self) -> String {
self.data.to_string()
impl std::fmt::Display for XmlData {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.data)
}
}

Expand Down
20 changes: 10 additions & 10 deletions tests/bulk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::sync::Once;
use tiberius::{IntoSql, Result, TokenRow};

#[cfg(all(feature = "tds73", feature = "chrono"))]
use chrono::NaiveDateTime;
use chrono::DateTime;

use runtimes_macro::test_on_runtimes;

Expand Down Expand Up @@ -150,61 +150,61 @@ test_bulk_type!(varchar_limited(
test_bulk_type!(datetime2(
"DATETIME2",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_0(
"DATETIME2(0)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_1(
"DATETIME2(1)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_2(
"DATETIME2(2)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_3(
"DATETIME2(3)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_4(
"DATETIME2(4)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_5(
"DATETIME2(5)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_6(
"DATETIME2(6)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));

#[cfg(all(feature = "tds73", feature = "chrono"))]
test_bulk_type!(datetime2_7(
"DATETIME2(7)",
100,
vec![NaiveDateTime::from_timestamp_opt(1658524194, 123456789).unwrap(); 100].into_iter()
vec![DateTime::from_timestamp(1658524194, 123456789); 100].into_iter()
));
6 changes: 3 additions & 3 deletions tests/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2237,7 +2237,7 @@ where
.unwrap()
.and_hms_opt(16, 20, 0)
.unwrap();
let dt: DateTime<Utc> = DateTime::from_utc(naive, Utc);
let dt: DateTime<Utc> = DateTime::from_naive_utc_and_offset(naive, Utc);

let row = conn
.query("SELECT @P1", &[&dt])
Expand Down Expand Up @@ -2276,7 +2276,7 @@ where
.unwrap();

let fixed = FixedOffset::east_opt(3600 * 3).unwrap();
let dt: DateTime<FixedOffset> = DateTime::from_utc(naive, fixed);
let dt: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(naive, fixed);

let row = conn
.query("SELECT @P1", &[&dt])
Expand Down Expand Up @@ -2314,7 +2314,7 @@ where
.and_hms_opt(16, 20, 0)
.unwrap();
let fixed = FixedOffset::east_opt(3600 * 3).unwrap();
let dt: DateTime<FixedOffset> = DateTime::from_utc(naive, fixed);
let dt: DateTime<FixedOffset> = DateTime::from_naive_utc_and_offset(naive, fixed);

let row = conn
.query(format!("SELECT CAST('{}' AS datetimeoffset(7))", dt), &[])
Expand Down

0 comments on commit 5595382

Please sign in to comment.