mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-26 12:05:05 +08:00
remove the warnings
This commit is contained in:
parent
2ae0806773
commit
c6f4fb5f7d
@ -47,7 +47,7 @@ pub enum Version {
|
|||||||
pub(crate) mod test {
|
pub(crate) mod test {
|
||||||
use std::{
|
use std::{
|
||||||
fs::File,
|
fs::File,
|
||||||
io::{Read, Seek, SeekFrom},
|
io::{Seek, SeekFrom},
|
||||||
str::FromStr,
|
str::FromStr,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -136,58 +136,3 @@ impl std::ops::Deref for IndexUid {
|
|||||||
&self.0
|
&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(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
fs::{self, File},
|
fs::{self, File},
|
||||||
io::{BufReader, BufWriter, Read, Write},
|
io::{BufWriter, Write},
|
||||||
path::PathBuf,
|
path::PathBuf,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user