puccini_csar/errors/
invalid_key.rs1use {
2 depiction::*,
3 std::{fmt, io},
4 thiserror::*,
5};
6
7#[derive(Debug, Error)]
13pub struct InvalidKeyError {
14 pub keyname: String,
16
17 pub reason: String,
19}
20
21impl InvalidKeyError {
22 pub fn new(keyname: String, reason: String) -> Self {
24 Self { keyname, reason: reason }
25 }
26}
27
28impl fmt::Display for InvalidKeyError {
29 fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
30 write!(formatter, "{}: {}", self.keyname, self.reason)
31 }
32}
33
34impl Depict for InvalidKeyError {
35 fn depict<WriteT>(&self, writer: &mut WriteT, context: &DepictionContext) -> io::Result<()>
36 where
37 WriteT: io::Write,
38 {
39 context.separate(writer)?;
40 write!(writer, "{} invalid: {}", context.theme.meta(&self.keyname), context.theme.error(&self.reason))
41 }
42}