diff --git a/Cargo.lock.msrv b/Cargo.lock.msrv index 30d6b4a..964728a 100644 --- a/Cargo.lock.msrv +++ b/Cargo.lock.msrv @@ -25,6 +25,7 @@ dependencies = [ "env_logger", "log", "once_cell", + "thiserror", ] [[package]] @@ -121,6 +122,24 @@ version = "1.18.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd8b5dd2ae5ed71462c540258bedcb51965123ad7e7ccf4b9a8cafaa4a63576d" +[[package]] +name = "proc-macro2" +version = "1.0.78" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quote" +version = "1.0.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +dependencies = [ + "proc-macro2", +] + [[package]] name = "regex" version = "1.10.2" @@ -163,6 +182,17 @@ dependencies = [ "windows-sys", ] +[[package]] +name = "syn" +version = "2.0.52" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b699d15b36d1f02c3e7c69f8ffef53de37aefae075d8488d4ba1a7788d574a07" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "termcolor" version = "1.3.0" @@ -172,6 +202,32 @@ dependencies = [ "winapi-util", ] +[[package]] +name = "thiserror" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e45bcbe8ed29775f228095caf2cd67af7a4ccf756ebff23a306bf3e8b47b24b" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.57" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a953cb265bef375dae3de6663da4d3804eee9682ea80d8e2542529b73c531c81" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "unicode-ident" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + [[package]] name = "winapi" version = "0.3.9" diff --git a/Cargo.toml b/Cargo.toml index a620578..a78efaa 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,8 +12,9 @@ repository = "https://github.com/ystreet/cdp-types" rust-version = "1.65.0" [dependencies] -log = "0.4" cea708-types = "0.3" +log = "0.4" +thiserror = "1" [dev-dependencies] once_cell = "1" diff --git a/src/lib.rs b/src/lib.rs index ed4e90b..2d9bde3 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,9 +14,10 @@ extern crate log; /// Various possible errors when parsing data -#[derive(Debug, Clone, Copy, PartialEq, Eq)] +#[derive(Debug, Clone, Copy, PartialEq, Eq, thiserror::Error)] pub enum ParserError { /// The length of the data does not match the length in the data + #[error("The length of the data ({actual}) does not match the advertised expected ({expected}) length")] LengthMismatch { /// Expected minimum size of the data expected: usize, @@ -24,17 +25,23 @@ pub enum ParserError { actual: usize, }, /// Some magic byte/s do not have the correct value + #[error("Some magic byte/s do not have the correct value")] WrongMagic, /// Unrecognied framerate value + #[error("The framerate specified is not known by this implementation")] UnknownFramerate, /// Some 'fixed' bits did not have the correct value + #[error("Some fixed bits did not have the correct value")] InvalidFixedBits, /// CEA-608 bytes were found after CEA-708 bytes + #[error("CEA-608 compatibility bytes were found after CEA-708 bytes")] Cea608AfterCea708, /// Failed to validate the checksum + #[error("The computed checksum value does not match the stored checksum value")] ChecksumFailed, /// Sequence count differs between the header and the footer. Usually indicates this packet was /// spliced together incorrectly. + #[error("The sequence count differs between the header and the footer")] SequenceCountMismatch, } @@ -51,20 +58,7 @@ impl From for ParserError { } } -impl std::fmt::Display for ParserError { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.pad(&format!("{self:?}")) - } -} - -/// An error enum returned when writing data fails -#[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum WriterError { - /// Writing would overflow by how many bytes - WouldOverflow(usize), - /// It is not possible to write to this resource - ReadOnly, -} +pub use cea708_types::WriterError; static FRAMERATES: [Framerate; 8] = [ Framerate {