From 8bf4219c53ac59fbb5fed6519bf091dd912863f1 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Mon, 23 Oct 2023 17:26:40 -0700 Subject: [PATCH 01/24] remove num_enum --- Cargo.lock | 58 ------------------------------- rust/candid/Cargo.toml | 1 - rust/candid/src/types/internal.rs | 3 +- 3 files changed, 1 insertion(+), 61 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8b07d2e9..780cbfe3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -271,7 +271,6 @@ dependencies = [ "leb128", "num-bigint", "num-traits", - "num_enum", "paste", "pretty 0.12.3", "rand", @@ -1104,27 +1103,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_enum" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a015b430d3c108a207fd776d2e2196aaf8b1cf8cf93253e3a097ff3085076a1" -dependencies = [ - "num_enum_derive", -] - -[[package]] -name = "num_enum_derive" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96667db765a921f7b295ffee8b60472b686a51d4f21c2ee4ffdb94c7013b65a6" -dependencies = [ - "proc-macro-crate", - "proc-macro2 1.0.69", - "quote 1.0.33", - "syn 2.0.38", -] - [[package]] name = "once_cell" version = "1.18.0" @@ -1345,16 +1323,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bc5c99d529f0d30937f6f4b8a86d988047327bb88d04d2c4afc356de74722131" -[[package]] -name = "proc-macro-crate" -version = "1.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" -dependencies = [ - "once_cell", - "toml_edit", -] - [[package]] name = "proc-macro2" version = "0.4.30" @@ -1890,23 +1858,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" -[[package]] -name = "toml_datetime" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3550f4e9685620ac18a50ed434eb3aec30db8ba93b0287467bca5826ea25baf1" - -[[package]] -name = "toml_edit" -version = "0.19.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" -dependencies = [ - "indexmap 2.0.2", - "toml_datetime", - "winnow", -] - [[package]] name = "typed-arena" version = "2.0.2" @@ -2241,12 +2192,3 @@ name = "windows_x86_64_msvc" version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" - -[[package]] -name = "winnow" -version = "0.5.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3b801d0e0a6726477cc207f60162da452f3a95adb368399bef20a946e06f65c" -dependencies = [ - "memchr", -] diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index ffb2a6b8..4dc2483a 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -20,7 +20,6 @@ codespan-reporting = "0.11" hex = "0.4.2" ic_principal = { path = "../ic_principal", version = "0.1.0" } leb128 = "0.2.4" -num_enum = "0.6.1" num-bigint = { version = "0.4.2", features = ["serde"] } num-traits = "0.2.12" paste = "1.0.0" diff --git a/rust/candid/src/types/internal.rs b/rust/candid/src/types/internal.rs index 9c296d36..13eb0f91 100644 --- a/rust/candid/src/types/internal.rs +++ b/rust/candid/src/types/internal.rs @@ -1,6 +1,5 @@ use super::CandidType; use crate::idl_hash; -use num_enum::TryFromPrimitive; use std::cell::RefCell; use std::collections::HashMap; use std::fmt; @@ -518,7 +517,7 @@ macro_rules! service { }} } -#[derive(Debug, PartialEq, TryFromPrimitive)] +#[derive(Debug, PartialEq)] #[repr(i64)] pub enum Opcode { Null = -1, From b5bee343ab4c574a7bd4917e6d94024b2be040d0 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Mon, 23 Oct 2023 18:10:10 -0700 Subject: [PATCH 02/24] clean up parser dependencies --- Cargo.lock | 3 --- Cargo.toml | 8 ++++++++ rust/candid/Cargo.toml | 18 +++++++++--------- rust/candid_parser/Cargo.toml | 20 ++++++++------------ 4 files changed, 25 insertions(+), 24 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 780cbfe3..b1e3032e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -312,10 +312,7 @@ dependencies = [ "pretty 0.12.3", "rand", "serde", - "serde_bytes", "serde_dhall", - "sha2 0.10.8", - "stacker", "test-generator", "thiserror", ] diff --git a/Cargo.toml b/Cargo.toml index eecbc858..6465cf43 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,11 @@ members = [ ] resolver = "2" +[workspace.dependencies] +hex = "0.4.2" +num-bigint = { version = "0.4.2", features = ["serde"] } +num-traits = "0.2.12" +pretty = "0.12.0" +serde = { version = "1.0.118", features = ["derive"] } +thiserror = "1.0.20" +anyhow = "1.0" diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index 4dc2483a..a6824561 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -14,20 +14,20 @@ keywords = ["internet-computer", "idl", "candid", "dfinity"] include = ["src", "Cargo.toml", "LICENSE", "README.md"] [dependencies] -byteorder = "1.4.3" candid_derive = { path = "../candid_derive", version = "=0.6.4" } -codespan-reporting = "0.11" -hex = "0.4.2" ic_principal = { path = "../ic_principal", version = "0.1.0" } +byteorder = "1.4.3" +codespan-reporting = "0.11" +hex.workspace = true leb128 = "0.2.4" -num-bigint = { version = "0.4.2", features = ["serde"] } -num-traits = "0.2.12" +num-bigint.workspace = true +num-traits.workspace = true paste = "1.0.0" -pretty = "0.12.0" -serde = { version = "1.0.118", features = ["derive"] } +pretty.workspace = true +serde.workspace = true serde_bytes = "0.11" -thiserror = "1.0.20" -anyhow = "1.0" +thiserror.workspace = true +anyhow.workspace = true binread = { version = "2.1", features = ["debug_template"] } [target.'cfg(not(target_arch = "wasm32"))'.dependencies] diff --git a/rust/candid_parser/Cargo.toml b/rust/candid_parser/Cargo.toml index eac40b32..f58a7485 100644 --- a/rust/candid_parser/Cargo.toml +++ b/rust/candid_parser/Cargo.toml @@ -20,15 +20,11 @@ lalrpop = "0.20.0" [dependencies] candid = { path = "../candid", version = "0.10" } codespan-reporting = "0.11" -hex = "0.4.2" -num-bigint = { version = "0.4.2", features = ["serde"] } -num-traits = "0.2.12" -pretty = "0.12.0" -serde = { version = "1.0.118", features = ["derive"] } -serde_bytes = "0.11" -sha2 = "0.10.1" -thiserror = "1.0.20" -anyhow = "1.0" +hex.workspace = true +num-bigint.workspace = true +pretty.workspace = true +thiserror.workspace = true +anyhow.workspace = true lalrpop-util = "0.20.0" logos = "0.13" @@ -39,9 +35,9 @@ arbitrary = { version = "1.0", optional = true } serde_dhall = { version = "0.11", default-features = false, optional = true } fake = { version = "2.4", optional = true } rand = { version = "0.8", optional = true } +num-traits = { workspace = true, optional = true } +serde = { workspace = true, optional = true } -[target.'cfg(not(target_arch = "wasm32"))'.dependencies] -stacker = "0.1" [dev-dependencies] goldenfile = "1.1.0" @@ -50,7 +46,7 @@ rand = "0.8" [features] configs = ["serde_dhall"] -random = ["configs", "arbitrary", "fake", "rand"] +random = ["configs", "arbitrary", "fake", "rand", "num-traits", "serde"] all = ["random"] # docs.rs-specific configuration From de8d5223c293ed6a3710228307bd277c2173f4f4 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Mon, 23 Oct 2023 18:37:35 -0700 Subject: [PATCH 03/24] checkpoint --- Cargo.toml | 1 + rust/candid/Cargo.toml | 13 +++++++++---- rust/candid/src/types/impls.rs | 2 ++ rust/candid/src/types/mod.rs | 2 ++ rust/candid_parser/Cargo.toml | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6465cf43..807f349d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,4 @@ pretty = "0.12.0" serde = { version = "1.0.118", features = ["derive"] } thiserror = "1.0.20" anyhow = "1.0" +rand = "0.8" diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index a6824561..de536cd6 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -20,21 +20,22 @@ byteorder = "1.4.3" codespan-reporting = "0.11" hex.workspace = true leb128 = "0.2.4" -num-bigint.workspace = true -num-traits.workspace = true paste = "1.0.0" pretty.workspace = true serde.workspace = true -serde_bytes = "0.11" thiserror.workspace = true anyhow.workspace = true binread = { version = "2.1", features = ["debug_template"] } +serde_bytes = { version = "0.11", optional = true } +num-bigint = { workspace = true } +num-traits= { workspace = true } + [target.'cfg(not(target_arch = "wasm32"))'.dependencies] stacker = "0.1" [dev-dependencies] -rand = "0.8" +rand.workspace = true criterion = "0.4" serde_cbor = "0.11.2" serde_json = "1.0.74" @@ -47,3 +48,7 @@ path = "benches/benchmark.rs" [features] mute_warnings = [] +#bignum = ["num-bigint", "num-traits"] +#value = ["bignum"] +default = ["serde_bytes"] + diff --git a/rust/candid/src/types/impls.rs b/rust/candid/src/types/impls.rs index 3caf1077..bd9156d1 100644 --- a/rust/candid/src/types/impls.rs +++ b/rust/candid/src/types/impls.rs @@ -140,6 +140,7 @@ where Ok(()) } } +#[cfg(feature = "serde_bytes")] impl CandidType for serde_bytes::ByteBuf { fn _ty() -> Type { TypeInner::Vec(TypeInner::Nat8.into()).into() @@ -151,6 +152,7 @@ impl CandidType for serde_bytes::ByteBuf { serializer.serialize_blob(self.as_slice()) } } +#[cfg(feature = "serde_bytes")] impl CandidType for serde_bytes::Bytes { fn _ty() -> Type { TypeInner::Vec(TypeInner::Nat8.into()).into() diff --git a/rust/candid/src/types/mod.rs b/rust/candid/src/types/mod.rs index edcc3a09..c962d657 100644 --- a/rust/candid/src/types/mod.rs +++ b/rust/candid/src/types/mod.rs @@ -10,6 +10,7 @@ mod impls; pub mod internal; pub mod subtype; pub mod type_env; +//#[cfg(feature = "value")] pub mod value; pub use self::internal::{ @@ -17,6 +18,7 @@ pub use self::internal::{ }; pub use type_env::TypeEnv; +//#[cfg(feature = "bignum")] pub mod number; pub mod principal; pub mod reference; diff --git a/rust/candid_parser/Cargo.toml b/rust/candid_parser/Cargo.toml index f58a7485..de51ab64 100644 --- a/rust/candid_parser/Cargo.toml +++ b/rust/candid_parser/Cargo.toml @@ -42,7 +42,7 @@ serde = { workspace = true, optional = true } [dev-dependencies] goldenfile = "1.1.0" test-generator = "0.3.0" -rand = "0.8" +rand.workspace = true [features] configs = ["serde_dhall"] From a740ed9fbe4d546c6f7519b75e0afe8e2cc639f3 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Mon, 23 Oct 2023 21:51:12 -0700 Subject: [PATCH 04/24] value feature --- Changelog.md | 3 ++- rust/candid/Cargo.toml | 14 +++++++++++++- rust/candid/src/de.rs | 10 ++++++++-- rust/candid/src/lib.rs | 5 +++-- rust/candid/src/pretty_printer.rs | 20 ++++++++++++++++++-- rust/candid/src/ser.rs | 3 +++ rust/candid/src/types/internal.rs | 2 +- rust/candid/src/types/mod.rs | 3 +-- rust/candid/src/types/number.rs | 16 +--------------- rust/candid_parser/Cargo.toml | 2 +- 10 files changed, 51 insertions(+), 27 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1d02bc51..d4e75840 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,7 +5,8 @@ * The original `candid` crate is split into three crates: * `candid`: mainly for Candid data (de-)serialization. - + `candid::bindings::candid` becomes `candid::pretty_printer`. + + `candid::bindings::candid` moves to `candid::pretty_printer`. + + `candid::types::number::pp_num_str` moves to `candid::pretty_printer::pp_num_str`. * `candid_parser`: used to be the `parser` and `bindings` module in `candid` crate. + Remove `FromStr` trait for `IDLArgs` and `IDLValue`. Use `parse_idl_args` and `parse_idl_value` respectively instead. + `TypeEnv.ast_to_type` becomes `candid_parser::typing::ast_to_type`. diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index de536cd6..9b6d8fe4 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -49,6 +49,18 @@ path = "benches/benchmark.rs" [features] mute_warnings = [] #bignum = ["num-bigint", "num-traits"] -#value = ["bignum"] +value = [] default = ["serde_bytes"] +all = ["default", "value"] +[[test]] +name = "types" +path = "tests/types.rs" +required-features = ["value"] + +# docs.rs-specific configuration +# To test locally: RUSTDOCFLAGS="--cfg docsrs" cargo +nightly doc --features all +[package.metadata.docs.rs] +features = ["all"] +# defines the configuration attribute `docsrs` +rustdoc-args = ["--cfg", "docsrs"] diff --git a/rust/candid/src/de.rs b/rust/candid/src/de.rs index 036440c6..ea512270 100644 --- a/rust/candid/src/de.rs +++ b/rust/candid/src/de.rs @@ -56,6 +56,7 @@ impl<'de> IDLDeserialize<'de> { self.de.is_untyped = false; self.deserialize_with_type(T::ty()) } + #[cfg(feature = "value")] pub fn get_value_with_type( &mut self, env: &TypeEnv, @@ -449,14 +450,19 @@ impl<'de> Deserializer<'de> { { use de::Deserializer; let tid = type_of(&visitor); - if tid != TypeId::of::() // derive Copy - && tid != TypeId::of::() // derive Copy + if tid != TypeId::of::() // derive Copy // OptionVisitor doesn't derive Copy, but has only PhantomData. // OptionVisitor is private and we cannot get TypeId of OptionVisitor, // we also cannot downcast V to concrete type, because of 'de // The only option left seems to be type_name, but it is not guaranteed to be stable, so there is risk here. && !tid.name.starts_with("serde::de::impls::OptionVisitor<") { + #[cfg(feature = "value")] + if tid != TypeId::of::() { + // derive Copy + panic!("Not a valid visitor: {tid:?}"); + } + #[cfg(not(feature = "value"))] panic!("Not a valid visitor: {tid:?}"); } // This is safe, because the visitor either impl Copy or is zero sized diff --git a/rust/candid/src/lib.rs b/rust/candid/src/lib.rs index c4d5217a..55b557e4 100644 --- a/rust/candid/src/lib.rs +++ b/rust/candid/src/lib.rs @@ -229,15 +229,16 @@ pub mod error; pub use error::{Error, Result}; pub mod types; +pub use types::number::{Int, Nat}; +#[cfg(feature = "value")] +pub use types::value::{IDLArgs, IDLValue}; pub use types::CandidType; pub use types::{ arc, - number::{Int, Nat}, principal::Principal, rc, reference::{Func, Service}, reserved::{Empty, Reserved}, - value::{IDLArgs, IDLValue}, TypeEnv, }; diff --git a/rust/candid/src/pretty_printer.rs b/rust/candid/src/pretty_printer.rs index fd513436..b440f8a9 100644 --- a/rust/candid/src/pretty_printer.rs +++ b/rust/candid/src/pretty_printer.rs @@ -210,15 +210,31 @@ pub fn compile(env: &TypeEnv, actor: &Option) -> String { } } +pub fn pp_num_str(s: &str) -> String { + let mut groups = Vec::new(); + for chunk in s.as_bytes().rchunks(3) { + let str = String::from_utf8_lossy(chunk); + groups.push(str); + } + groups.reverse(); + if "-" == groups.first().unwrap() { + "-".to_string() + &groups[1..].join("_") + } else { + groups.join("_") + } +} + +#[cfg(feature = "value")] pub mod value { - use super::{ident_string, pp_text}; + use super::{ident_string, pp_num_str, pp_text}; use crate::pretty::*; use crate::types::value::{IDLArgs, IDLField, IDLValue}; - use crate::types::{number::pp_num_str, Label}; + use crate::types::Label; use std::fmt; use ::pretty::RcDoc; + // TODO config this const MAX_ELEMENTS_FOR_PRETTY_PRINT: usize = 10; impl fmt::Display for IDLArgs { diff --git a/rust/candid/src/ser.rs b/rust/candid/src/ser.rs index e36e7032..3c96b780 100644 --- a/rust/candid/src/ser.rs +++ b/rust/candid/src/ser.rs @@ -2,6 +2,7 @@ use super::error::{Error, Result}; use super::types; +#[cfg(feature = "value")] use super::types::value::IDLValue; use super::types::{internal::Opcode, Field, Type, TypeEnv, TypeInner}; use byteorder::{LittleEndian, WriteBytesExt}; @@ -33,12 +34,14 @@ impl IDLBuilder { value.idl_serialize(&mut self.value_ser)?; Ok(self) } + #[cfg(feature = "value")] pub fn value_arg<'a>(&'a mut self, value: &IDLValue) -> Result<&'a mut Self> { use super::CandidType; self.type_ser.push_type(&value.value_ty())?; value.idl_serialize(&mut self.value_ser)?; Ok(self) } + #[cfg(feature = "value")] /// Annotate IDLValue with (TypeEnv, Type). Note that the TypeEnv will be added to the serializer state. /// If the Type can already be resolved by previous TypeEnvs, you don't need to pass TypeEnv again. pub fn value_arg_with_type<'a>( diff --git a/rust/candid/src/types/internal.rs b/rust/candid/src/types/internal.rs index 13eb0f91..2bc6488c 100644 --- a/rust/candid/src/types/internal.rs +++ b/rust/candid/src/types/internal.rs @@ -374,7 +374,7 @@ impl std::fmt::Display for Label { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { Label::Id(n) | Label::Unnamed(n) => { - write!(f, "{}", super::number::pp_num_str(&n.to_string())) + write!(f, "{}", crate::pretty_printer::pp_num_str(&n.to_string())) } Label::Named(id) => write!(f, "{id}"), } diff --git a/rust/candid/src/types/mod.rs b/rust/candid/src/types/mod.rs index c962d657..094a15c7 100644 --- a/rust/candid/src/types/mod.rs +++ b/rust/candid/src/types/mod.rs @@ -10,7 +10,7 @@ mod impls; pub mod internal; pub mod subtype; pub mod type_env; -//#[cfg(feature = "value")] +#[cfg(feature = "value")] pub mod value; pub use self::internal::{ @@ -18,7 +18,6 @@ pub use self::internal::{ }; pub use type_env::TypeEnv; -//#[cfg(feature = "bignum")] pub mod number; pub mod principal; pub mod reference; diff --git a/rust/candid/src/types/number.rs b/rust/candid/src/types/number.rs index 75ca3de3..9cbe9a24 100644 --- a/rust/candid/src/types/number.rs +++ b/rust/candid/src/types/number.rs @@ -1,7 +1,7 @@ //! Data structure for Candid type Int, Nat, supporting big integer with LEB128 encoding. use super::{CandidType, Serializer, Type, TypeInner}; -use crate::Error; +use crate::{pretty_printer::pp_num_str, Error}; use num_bigint::{BigInt, BigUint}; use serde::{ de::{self, Deserialize, SeqAccess, Visitor}, @@ -88,20 +88,6 @@ impl std::str::FromStr for Nat { } } -pub fn pp_num_str(s: &str) -> String { - let mut groups = Vec::new(); - for chunk in s.as_bytes().rchunks(3) { - let str = String::from_utf8_lossy(chunk); - groups.push(str); - } - groups.reverse(); - if "-" == groups.first().unwrap() { - "-".to_string() + &groups[1..].join("_") - } else { - groups.join("_") - } -} - impl fmt::Display for Int { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let s = self.0.to_str_radix(10); diff --git a/rust/candid_parser/Cargo.toml b/rust/candid_parser/Cargo.toml index de51ab64..14cbd798 100644 --- a/rust/candid_parser/Cargo.toml +++ b/rust/candid_parser/Cargo.toml @@ -18,7 +18,7 @@ build = "build.rs" lalrpop = "0.20.0" [dependencies] -candid = { path = "../candid", version = "0.10" } +candid = { path = "../candid", version = "0.10", features = ["all"] } codespan-reporting = "0.11" hex.workspace = true num-bigint.workspace = true From e6f5413d123c495e217d82eb9a7bc576312055c2 Mon Sep 17 00:00:00 2001 From: Yan Chen Date: Tue, 24 Oct 2023 09:15:33 -0700 Subject: [PATCH 05/24] remove codespan --- Cargo.lock | 1 - rust/candid/Cargo.toml | 1 - rust/candid/src/error.rs | 41 +++++++++++++++++++++++++++++++--------- rust/candid/src/lib.rs | 5 ++++- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index b1e3032e..1a3f6128 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -264,7 +264,6 @@ dependencies = [ "binread", "byteorder", "candid_derive", - "codespan-reporting", "criterion", "hex", "ic_principal", diff --git a/rust/candid/Cargo.toml b/rust/candid/Cargo.toml index 9b6d8fe4..59fefe7a 100644 --- a/rust/candid/Cargo.toml +++ b/rust/candid/Cargo.toml @@ -17,7 +17,6 @@ include = ["src", "Cargo.toml", "LICENSE", "README.md"] candid_derive = { path = "../candid_derive", version = "=0.6.4" } ic_principal = { path = "../ic_principal", version = "0.1.0" } byteorder = "1.4.3" -codespan-reporting = "0.11" hex.workspace = true leb128 = "0.2.4" paste = "1.0.0" diff --git a/rust/candid/src/error.rs b/rust/candid/src/error.rs index 095b8208..db663896 100644 --- a/rust/candid/src/error.rs +++ b/rust/candid/src/error.rs @@ -1,16 +1,21 @@ //! `candid::Result = Result>` -use codespan_reporting::diagnostic::Label; use serde::{de, ser}; use std::{io, num::ParseIntError}; use thiserror::Error; pub type Result = std::result::Result; +#[derive(Debug)] +pub struct Label { + range: std::ops::Range, + message: String, +} + #[derive(Debug, Error)] pub enum Error { #[error("binary parser error: {}", .0.get(0).map(|f| format!("{} at byte offset {}", f.message, f.range.start/2)).unwrap_or_else(|| "io error".to_string()))] - Binread(Vec>), + Binread(Vec