Skip to main content

ts_fix/
error.rs

1//! Error type for the `ts-fix` crate.
2
3use thiserror::Error;
4
5/// Errors returned by [`crate::TsFixBuilder::build`] and [`crate::TsFix::push`].
6///
7/// `#[non_exhaustive]` so future variants (e.g. from new repair operations) are
8/// additive — callers must not match exhaustively.
9#[derive(Debug, Error)]
10#[non_exhaustive]
11pub enum Error {
12    /// The slice passed to [`crate::TsFix::push`] was not exactly 188 bytes.
13    ///
14    /// ISO/IEC 13818-1 §2.4.3.2 — TS packets are fixed at 188 bytes.
15    #[error("short packet: expected 188 bytes, got {len}")]
16    ShortPacket {
17        /// Actual length of the slice supplied by the caller.
18        len: usize,
19    },
20
21    /// The first byte of the packet was not the TS sync byte `0x47`.
22    ///
23    /// ISO/IEC 13818-1 §2.4.3.2 — `sync_byte == 0x47`.
24    #[error("missing TS sync byte: expected 0x47, got {found:#04x}")]
25    NoSyncByte {
26        /// The byte actually found at position 0.
27        found: u8,
28    },
29}