pgs_parse/pgs_error.rs
1//! # Error Handling Module
2//!
3//! This module defines the error types and result handling mechanisms used throughout the library.
4//! It includes custom errors specific to PGS processing and reuses standard Rust I/O errors where appropriate.
5use core::fmt;
6use std::array::TryFromSliceError;
7
8/// Enum representing different error types used in the library.
9///
10/// Variants:
11/// - `File(std::io::Error)`: Represents an error encountered while performing I/O operations.
12/// - `InvalidInputArray`: Indicates that an input array is invalid.
13/// - `ReadInvalidSegment`: Read operation encountered an invalid segment.
14/// - `InvalidSegmentDataLength`: Segment has an incorrect data length.
15/// - `IncompleteDisplaySet`: Indicates that the display set is incomplete.
16#[derive(Debug)]
17pub enum Error {
18 File(std::io::Error),
19 InvalidInputArray,
20 ReadInvalidSegment,
21 InvalidSegmentDataLength,
22 IncompleteDisplaySet
23}
24
25impl fmt::Display for Error {
26 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
27 write!(f, "{self:?}")
28 }
29}
30
31impl std::error::Error for Error {}
32
33impl From<std::io::Error> for Error {
34 fn from(value: std::io::Error) -> Self {
35 Error::File(value)
36 }
37}
38
39impl From<TryFromSliceError> for Error {
40 fn from(_: TryFromSliceError) -> Self {
41 Error::InvalidInputArray
42 }
43}
44
45/// A custom result type used throughout the library.
46pub type Result<T> = core::result::Result<T, Error>;