chiark / gitweb /
mformat: Provide Incompat, utility functions, LLE variant, etc.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 8 May 2022 11:51:22 +0000 (12:51 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Wed, 11 May 2022 22:18:07 +0000 (23:18 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/materials-format.rs
src/shapelib.rs

index 442fd7381f013bf9286db6b1a010e27f349aebe4..6a01201cea9f2b9a66385ad4f8eda602dfb9d405 100644 (file)
@@ -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<E> {
+  mformat: Version,
+  error: E,
+}
+impl<E> Display for Incompat<E> 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<E>(self, error: E) -> Incompat<E> {
+    Incompat { mformat: self, error }
+  }
+
+  pub fn err_mapper<E>(self) -> impl Fn(E) -> Incompat<E> {
+    move |error| self.incompat(error)
+  }
+}
+
 #[derive(Error,Debug,Clone,Copy,Serialize,Deserialize)]
 #[derive(Eq,PartialEq)]
 pub enum VersionError {
index 934a05a8cbe67e6291eb12d0ae4dd5b655f2d7b8..aa96ab0ca605fac736c6b3b351ec38067598501b 100644 (file)
@@ -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),