remove the warnings

This commit is contained in:
Tamo 2022-10-10 20:00:29 +02:00 committed by Clément Renault
parent 2ae0806773
commit c6f4fb5f7d
No known key found for this signature in database
GPG Key ID: 92ADA4E935E71FA4
3 changed files with 2 additions and 57 deletions

View File

@ -47,7 +47,7 @@ pub enum Version {
pub(crate) mod test {
use std::{
fs::File,
io::{Read, Seek, SeekFrom},
io::{Seek, SeekFrom},
str::FromStr,
};

View File

@ -136,58 +136,3 @@ impl std::ops::Deref for IndexUid {
&self.0
}
}
/// Serialize a `time::Duration` as a best effort ISO 8601 while waiting for
/// https://github.com/time-rs/time/issues/378.
/// This code is a port of the old code of time that was removed in 0.2.
#[cfg(test)]
fn serialize_duration<S: serde::Serializer>(
duration: &Option<time::Duration>,
serializer: S,
) -> Result<S::Ok, S::Error> {
use std::fmt::Write;
use time::Duration;
match duration {
Some(duration) => {
// technically speaking, negative duration is not valid ISO 8601
if duration.is_negative() {
return serializer.serialize_none();
}
const SECS_PER_DAY: i64 = Duration::DAY.whole_seconds();
let secs = duration.whole_seconds();
let days = secs / SECS_PER_DAY;
let secs = secs - days * SECS_PER_DAY;
let hasdate = days != 0;
let nanos = duration.subsec_nanoseconds();
let hastime = (secs != 0 || nanos != 0) || !hasdate;
// all the following unwrap can't fail
let mut res = String::new();
write!(&mut res, "P").unwrap();
if hasdate {
write!(&mut res, "{}D", days).unwrap();
}
const NANOS_PER_MILLI: i32 = Duration::MILLISECOND.subsec_nanoseconds();
const NANOS_PER_MICRO: i32 = Duration::MICROSECOND.subsec_nanoseconds();
if hastime {
if nanos == 0 {
write!(&mut res, "T{}S", secs).unwrap();
} else if nanos % NANOS_PER_MILLI == 0 {
write!(&mut res, "T{}.{:03}S", secs, nanos / NANOS_PER_MILLI).unwrap();
} else if nanos % NANOS_PER_MICRO == 0 {
write!(&mut res, "T{}.{:06}S", secs, nanos / NANOS_PER_MICRO).unwrap();
} else {
write!(&mut res, "T{}.{:09}S", secs, nanos).unwrap();
}
}
serializer.serialize_str(&res)
}
None => serializer.serialize_none(),
}
}

View File

@ -1,6 +1,6 @@
use std::{
fs::{self, File},
io::{BufReader, BufWriter, Read, Write},
io::{BufWriter, Write},
path::PathBuf,
};