substrate_data/wire/binary/
decode_error.rs1use std::fmt;
4
5#[derive(Debug, Clone, PartialEq, Eq)]
7pub struct DecodeError {
8 pub message: String,
10 pub offset: usize,
12}
13
14impl DecodeError {
15 pub(super) fn duplicate_key(key: &str, offset: usize) -> Self {
17 DecodeError {
18 message: format!("`{key}` is already set in this map"),
19 offset,
20 }
21 }
22}
23
24impl fmt::Display for DecodeError {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 write!(f, "byte {}: {}", self.offset, self.message)
27 }
28}
29
30impl std::error::Error for DecodeError {}