fn from(p: VisiblePieceId) -> String { format!("{}",p) }
}
+impl FromStr for VisiblePieceId {
+ type Err = AE;
+ fn from_str(s : &str) -> Result<VisiblePieceId,AE> {
+ let e = || anyhow!("could not deserialise visibile piece id");
+ let mut i = s.splitn(2,'.').map(|s| s.parse().map_err(|_| e()));
+ let h : u32 = i.next().ok_or_else(e)??;
+ let l : u32 = i.next().ok_or_else(e)??;
+ Ok(VisiblePieceId(((h as u64) << 32) | (l as u64)))
+ }
+//fn from(_: T) -> Self { todo!() }`
+}
+
struct VisiblePieceIdVisitor { }
impl<'de> serde::de::Visitor<'de> for VisiblePieceIdVisitor {
type Value = VisiblePieceId;
fn visit_str<DE>(self, s : &str) -> Result<VisiblePieceId, DE>
where DE: serde::de::Error,
{
- let e = || DE::custom("could not deserialise visibile piece id");
- let mut i = s.splitn(2,'.').map(|s| s.parse().map_err(|_| e()));
- let h : u32 = i.next().ok_or_else(e)??;
- let l : u32 = i.next().ok_or_else(e)??;
- Ok(VisiblePieceId(((h as u64) << 32) | (l as u64)))
+ s.parse().map_err(DE::custom)
}
}
pub use std::sync::{Arc,Mutex,RwLock};
pub use std::collections::HashMap;
pub use std::borrow::Borrow;
+pub use std::convert::TryFrom;
+pub use std::str::FromStr;
pub use thiserror::Error;
pub use anyhow::{Context,anyhow};
pub use crate::pieces::*;
pub type E = anyhow::Error;
+pub type AE = anyhow::Error;
pub type SvgData = Vec<u8>;
pub type Coord = isize;