From: Ian Jackson Date: Sun, 8 May 2022 11:51:22 +0000 (+0100) Subject: mformat: Provide Incompat, utility functions, LLE variant, etc. X-Git-Tag: otter-1.1.0~249 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=commitdiff_plain;h=e378eb7eeac997d42dff9f7fd23e3bcff64d5413;p=otter.git mformat: Provide Incompat, utility functions, LLE variant, etc. Signed-off-by: Ian Jackson --- diff --git a/src/materials-format.rs b/src/materials-format.rs index 442fd738..6a01201c 100644 --- a/src/materials-format.rs +++ b/src/materials-format.rs @@ -28,6 +28,35 @@ impl Default for Version { #[error(r#"unsupported bundle, library or spec format version "format={0}""#)] pub struct Unsupported(u32); +#[derive(Error,Debug,Copy,Clone,Serialize,Deserialize)] +pub struct Incompat { + mformat: Version, + error: E, +} +impl Display for Incompat where E: Display { + #[throws(fmt::Error)] + fn fmt(&self, f: &mut fmt::Formatter) { + if self.mformat == 1 { + write!(f, + r#"{}: not supported in format 1, maybe you forgoot "format="#, + self.error)?; + } else { + write!(f, + r#"{}: not supported with "format={}""#, + self.error, self.mformat)?; + } + } +} +impl Version { + pub fn incompat(self, error: E) -> Incompat { + Incompat { mformat: self, error } + } + + pub fn err_mapper(self) -> impl Fn(E) -> Incompat { + move |error| self.incompat(error) + } +} + #[derive(Error,Debug,Clone,Copy,Serialize,Deserialize)] #[derive(Eq,PartialEq)] pub enum VersionError { diff --git a/src/shapelib.rs b/src/shapelib.rs index 934a05a8..aa96ab0c 100644 --- a/src/shapelib.rs +++ b/src/shapelib.rs @@ -123,12 +123,22 @@ pub enum LibraryLoadError { FilesListFieldsMustBeAtStart(usize), #[error("piece defines multiple faces in multiple ways")] MultipleMultipleFaceDefinitions, + #[error("{0}")] + MaterialsFormatIncompat(#[from] materials_format::Incompat< + LibraryLoadMFIncompat + >), #[error("{0}")] BadSubstitution(#[from] SubstError), #[error("{0}")] UnsupportedColourSpec(#[from] UnsupportedColourSpec), #[error("bad item name (invalid characters) in {0:?}")] BadItemName(String), #[error("{0:?}")] MaterialsFormatVersionError(#[from] MFVE), } +#[derive(Error,Debug,Clone,Copy,Serialize,Deserialize)] +pub enum LibraryLoadMFIncompat { + #[error("bad scale definition")] Scale, +} +pub use LibraryLoadMFIncompat as LLMI; + #[derive(Error,Copy,Clone,Debug)] pub enum SubstErrorKind { #[error("missing or unrecognised token {0}")] MissingToken (&'static str),