bacon_cipher/
errors.rs

1// Copyright 2019 astonbitecode
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14use std::{fmt, result};
15use std::error::Error;
16
17pub type Result<T> = result::Result<T, BaconError>;
18
19#[derive(Debug, PartialEq, Eq, Clone)]
20pub enum BaconError {
21    GeneralError(String),
22    CodecError(String),
23    SteganographerError(String),
24}
25
26impl fmt::Display for BaconError {
27    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
28        match self {
29            &BaconError::GeneralError(ref message) => write!(f, "{}", message),
30            &BaconError::CodecError(ref message) => write!(f, "{}", message),
31            &BaconError::SteganographerError(ref message) => write!(f, "{}", message),
32        }
33    }
34}
35
36impl Error for BaconError {
37    fn description(&self) -> &str {
38        match *self {
39            BaconError::GeneralError(_) => "A general error occured",
40            BaconError::CodecError(_) => "An error coming from a codec occured",
41            BaconError::SteganographerError(_) => "An error coming from a steganographer occured",
42        }
43    }
44}