Skip to main content

substrate_data/forms/
read_error.rs

1//! [`ReadError`]: why a source file's bytes aren't a source.
2
3use std::fmt;
4
5use crate::binary::DecodeError;
6
7/// Why a source file's bytes aren't a source.
8#[derive(Debug, Clone, PartialEq, Eq)]
9pub enum ReadError {
10    /// Text that isn't UTF-8.
11    NotUtf8(std::str::Utf8Error),
12    /// The binary form, malformed.
13    Binary(DecodeError),
14}
15
16impl fmt::Display for ReadError {
17    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
18        match self {
19            ReadError::NotUtf8(e) => write!(f, "not UTF-8 text: {e}"),
20            ReadError::Binary(e) => write!(f, "malformed binary form: {e}"),
21        }
22    }
23}
24
25impl std::error::Error for ReadError {}