cubing_core/kpuzzle/packed/
errors.rs

1use std::fmt::Display;
2
3/// An error due to the structure of a [`KPattern`][`super::KPattern`] (such as invalid source JSON).
4#[derive(Debug)]
5pub struct InvalidKPatternDataError {
6    pub description: String,
7}
8
9// TODO: is Rust smart enough to optimize this using just the `From<&str>` Pattern?
10impl From<String> for InvalidKPatternDataError {
11    fn from(description: String) -> Self {
12        Self { description }
13    }
14}
15
16impl From<&str> for InvalidKPatternDataError {
17    fn from(description: &str) -> Self {
18        Self {
19            description: description.to_owned(),
20        }
21    }
22}
23
24impl Display for InvalidKPatternDataError {
25    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26        write!(f, "{}", self.description)
27    }
28}
29
30/// An error due to the structure of a [`KTransformation`][`super::KTransformation`] (such as invalid source JSON).
31#[derive(Debug)]
32pub struct InvalidKTransformationDataError {
33    pub description: String,
34}
35
36// TODO: is Rust smart enough to optimize this using just the `From<&str>` Pattern?
37impl From<String> for InvalidKTransformationDataError {
38    fn from(description: String) -> Self {
39        Self { description }
40    }
41}
42
43impl From<&str> for InvalidKTransformationDataError {
44    fn from(description: &str) -> Self {
45        Self {
46            description: description.to_owned(),
47        }
48    }
49}
50
51impl Display for InvalidKTransformationDataError {
52    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53        write!(f, "{}", self.description)
54    }
55}