use serde::de;
use std::hash::{Hash, Hasher};
pub type BoxError = Box<dyn std::error::Error>;
#[derive(Debug, Copy, Clone)]
pub struct StrByAddr<'a>(pub &'a str);
impl<'a> Hash for StrByAddr<'a> {
#[inline(always)]
fn hash<H: Hasher>(&self, state: &mut H) {
std::ptr::hash(self.0, state);
}
}
impl<'a> PartialEq for StrByAddr<'a> {
#[inline(always)]
fn eq(&self, other: &Self) -> bool {
std::ptr::addr_eq(self.0, other.0)
}
}
impl<'a> Eq for StrByAddr<'a> {}
pub trait MapAccessSerdeExt<'de>: de::MapAccess<'de> {
#[inline]
fn deserialize_once_into_option<T>(
&mut self,
slot: &mut Option<T>,
field_name: &'static str,
) -> Result<(), Self::Error>
where
T: serde::Deserialize<'de>,
{
if slot.is_some() {
return Err(de::Error::duplicate_field(field_name));
}
*slot = self.next_value::<Option<T>>()?;
Ok(())
}
}
impl<'de, A> MapAccessSerdeExt<'de> for A where A: de::MapAccess<'de> {}