mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-04-01 21:13:09 +00:00
use btreemap instead of indexmap
to establish canonical lock ordering
This commit is contained in:
committed by
Aiden McClelland
parent
a28f6ca5e2
commit
1a86f393d6
@@ -704,7 +704,68 @@ impl<H: Digest, W: std::io::Write> std::io::Write for HashWriter<H, W> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub fn deserialize_number_permissive<
|
||||
'de,
|
||||
D: serde::de::Deserializer<'de>,
|
||||
T: FromStr<Err = E> + num::cast::FromPrimitive,
|
||||
E: std::fmt::Display,
|
||||
>(
|
||||
deserializer: D,
|
||||
) -> std::result::Result<T, D::Error> {
|
||||
use num::cast::FromPrimitive;
|
||||
|
||||
struct Visitor<T: FromStr<Err = E> + num::cast::FromPrimitive, E>(std::marker::PhantomData<T>);
|
||||
impl<'de, T: FromStr<Err = Err> + num::cast::FromPrimitive, Err: std::fmt::Display>
|
||||
serde::de::Visitor<'de> for Visitor<T, Err>
|
||||
{
|
||||
type Value = T;
|
||||
fn expecting(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(formatter, "a parsable string")
|
||||
}
|
||||
fn visit_str<E>(self, v: &str) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
v.parse().map_err(|e| serde::de::Error::custom(e))
|
||||
}
|
||||
fn visit_f64<E>(self, v: f64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
T::from_f64(v).ok_or_else(|| {
|
||||
serde::de::Error::custom(format!(
|
||||
"{} cannot be represented by the requested type",
|
||||
v
|
||||
))
|
||||
})
|
||||
}
|
||||
fn visit_u64<E>(self, v: u64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
T::from_u64(v).ok_or_else(|| {
|
||||
serde::de::Error::custom(format!(
|
||||
"{} cannot be represented by the requested type",
|
||||
v
|
||||
))
|
||||
})
|
||||
}
|
||||
fn visit_i64<E>(self, v: i64) -> Result<Self::Value, E>
|
||||
where
|
||||
E: serde::de::Error,
|
||||
{
|
||||
T::from_i64(v).ok_or_else(|| {
|
||||
serde::de::Error::custom(format!(
|
||||
"{} cannot be represented by the requested type",
|
||||
v
|
||||
))
|
||||
})
|
||||
}
|
||||
}
|
||||
deserializer.deserialize_str(Visitor(std::marker::PhantomData))
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
||||
pub struct Port(pub u16);
|
||||
impl<'de> Deserialize<'de> for Port {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
@@ -712,7 +773,7 @@ impl<'de> Deserialize<'de> for Port {
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
//TODO: if number, be permissive
|
||||
deserialize_from_str(deserializer).map(Port)
|
||||
deserialize_number_permissive(deserializer).map(Port)
|
||||
}
|
||||
}
|
||||
impl Serialize for Port {
|
||||
|
||||
Reference in New Issue
Block a user