tp_trie/
error.rs

1// This file is part of Tetcore.
2
3// Copyright (C) 2015-2021 Parity Technologies (UK) Ltd.
4// SPDX-License-Identifier: Apache-2.0
5
6// Licensed under the Apache License, Version 2.0 (the "License");
7// you may not use this file except in compliance with the License.
8// You may obtain a copy of the License at
9//
10// 	http://www.apache.org/licenses/LICENSE-2.0
11//
12// Unless required by applicable law or agreed to in writing, software
13// distributed under the License is distributed on an "AS IS" BASIS,
14// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15// See the License for the specific language governing permissions and
16// limitations under the License.
17
18#[cfg(feature="std")]
19use std::fmt;
20#[cfg(feature="std")]
21use std::error::Error as StdError;
22
23#[derive(Debug, PartialEq, Eq, Clone)]
24/// Error for trie node decoding.
25pub enum Error {
26	/// Bad format.
27	BadFormat,
28	/// Decoding error.
29	Decode(codec::Error)
30}
31
32impl From<codec::Error> for Error {
33	fn from(x: codec::Error) -> Self {
34		Error::Decode(x)
35	}
36}
37
38#[cfg(feature="std")]
39impl StdError for Error {
40	fn description(&self) -> &str {
41		match self {
42			Error::BadFormat => "Bad format error",
43			Error::Decode(_) => "Decoding error",
44		}
45	}
46}
47
48#[cfg(feature="std")]
49impl fmt::Display for Error {
50	fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
51		match self {
52			Error::Decode(e) => write!(f, "Decode error: {}", e),
53			Error::BadFormat => write!(f, "Bad format"),
54		}
55	}
56}