Skip to main content

mtb_align/
error.rs

1use std::fmt;
2
3/// What can be wrong with a set of exposures.
4///
5/// Only the arguments a caller takes from its own user are reported this way.
6/// A buffer whose length contradicts the dimensions passed with it stays a
7/// panic, because nothing downstream can do anything about it.
8#[derive(Clone, Copy, Debug, PartialEq, Eq)]
9pub enum Error {
10    /// Two exposures are not the same size.
11    SizeMismatch {
12        reference: (usize, usize),
13        target: (usize, usize),
14    },
15    /// The chosen reference is not one of the exposures.
16    NoSuchReference { reference: usize, exposures: usize },
17}
18
19impl fmt::Display for Error {
20    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
21        match *self {
22            Error::SizeMismatch { reference, target } => write!(
23                f,
24                "cannot align a {}x{} exposure against a {}x{} one",
25                reference.0, reference.1, target.0, target.1
26            ),
27            Error::NoSuchReference {
28                reference,
29                exposures,
30            } => write!(f, "no exposure {reference} in a stack of {exposures}"),
31        }
32    }
33}
34
35impl std::error::Error for Error {}