use std::num::{TryFromIntError, Wrapping};
use std::str;
use fehler::{throw, throws};
-use serde::{Serialize, Serializer, Deserialize};
+use serde::{Serialize, Serializer, Deserialize, Deserializer};
use thiserror::Error;
//---------- core definitions ----------
const LIMB_MODULUS : LimbVal = Wrapping(RAW_LIMB_MODULUS);
const LIMB_MASK : LimbVal = Wrapping(RAW_LIMB_MODULUS-1);
-#[derive(Deserialize)]
-#[serde(try_from="&str")]
pub struct ZCoord(innards::Innards);
#[derive(Error,Clone,Copy,Debug,Eq,PartialEq,Serialize,Deserialize)]
}
}
+impl<'de> Deserialize<'de> for ZCoord {
+ fn deserialize<D:Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
+ use serde::de::{Visitor, Error, Unexpected};
+ struct V;
+ impl<'de> Visitor<'de> for V {
+ type Value = ZCoord;
+ fn expecting(&self, f: &mut Formatter) -> fmt::Result {
+ write!(f, "a z coordinate (as a string)")
+ }
+ fn visit_str<E:Error>(self, s: &str) -> Result<Self::Value, E> {
+ ZCoord::from_str(s).map_err(|ParseError| Error::invalid_value(
+ Unexpected::Str(s), &self
+ ))
+ }
+ }
+ d.deserialize_str(V)
+ }
+}
+
//---------- construction of ZCoord contents ---------
//
// We can panic if this code is buggy, but not compromise safety.