diff --git a/crates/contracts/src/jetton/wallet.rs b/crates/contracts/src/jetton/wallet.rs index 149040c..38a704f 100644 --- a/crates/contracts/src/jetton/wallet.rs +++ b/crates/contracts/src/jetton/wallet.rs @@ -7,7 +7,7 @@ use tlb::{ r#as::{Remainder, VarInt}, ser::{BitPack, BitWriter, BitWriterExt}, }, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, either::Either, r#as::{EitherInlineOrRef, ParseFully, Ref, Same}, ser::{CellBuilder, CellBuilderError, CellSerialize}, @@ -67,7 +67,7 @@ where P: CellDeserialize<'de>, F: CellDeserialize<'de>, { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { // transfer#0f8a7ea5 parser.unpack::>()?; Ok(Self { @@ -118,7 +118,7 @@ impl<'de, F> CellDeserialize<'de> for ForwardPayload where F: CellDeserialize<'de>, { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { if parser.bits_left() >= bits_of::() // clone, so we don't advance original parser && parser.clone().unpack::()? == Self::COMMENT_PREFIX @@ -207,7 +207,7 @@ impl<'de, P> CellDeserialize<'de> for JettonTransferNotification

where P: CellDeserialize<'de>, { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.unpack::>()?; Ok(Self { query_id: parser.unpack()?, @@ -253,7 +253,7 @@ impl<'de, P> CellDeserialize<'de> for JettonBurn

where P: CellDeserialize<'de>, { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.unpack::>()?; Ok(Self { query_id: parser.unpack()?, diff --git a/crates/contracts/src/wallet/v4r2/mod.rs b/crates/contracts/src/wallet/v4r2/mod.rs index 1077b16..4aa13e5 100644 --- a/crates/contracts/src/wallet/v4r2/mod.rs +++ b/crates/contracts/src/wallet/v4r2/mod.rs @@ -7,7 +7,7 @@ use nacl::sign::PUBLIC_KEY_LENGTH; use num_bigint::BigUint; use tlb::{ bits::{de::BitReaderExt, ser::BitWriterExt}, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{NoArgs, Ref}, ser::{CellBuilder, CellBuilderError, CellSerialize}, Cell, Error, @@ -93,7 +93,7 @@ impl CellSerialize for WalletV4R2Data { } impl<'de> CellDeserialize<'de> for WalletV4R2Data { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { seqno: parser.unpack()?, wallet_id: parser.unpack()?, @@ -127,7 +127,7 @@ impl CellSerialize for WalletV4R2SignBody { } impl<'de> CellDeserialize<'de> for WalletV4R2SignBody { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { wallet_id: parser.unpack()?, expire_at: parser.unpack_as::<_, UnixTimestamp>()?, @@ -167,7 +167,7 @@ impl CellSerialize for WalletV4R2Op { } impl<'de> CellDeserialize<'de> for WalletV4R2Op { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(match parser.unpack()? { Self::SEND_PREFIX => Self::Send( iter::from_fn(|| { @@ -216,7 +216,7 @@ where IC: CellDeserialize<'de>, ID: CellDeserialize<'de>, { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { plugin_workchain: parser.unpack()?, plugin_balance: parser.unpack_as::<_, Grams>()?, @@ -245,7 +245,7 @@ impl CellSerialize for WalletV4R2OpPlugin { } impl<'de> CellDeserialize<'de> for WalletV4R2OpPlugin { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { plugin_address: MsgAddress { workchain_id: parser.unpack::()? as i32, @@ -273,7 +273,7 @@ impl CellSerialize for WalletV4R2ExternalBody { impl<'de> CellDeserialize<'de> for WalletV4R2ExternalBody { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { signature: parser.unpack()?, body: parser.parse()?, diff --git a/crates/contracts/src/wallet/v5r1/mod.rs b/crates/contracts/src/wallet/v5r1/mod.rs index a776060..201d03a 100644 --- a/crates/contracts/src/wallet/v5r1/mod.rs +++ b/crates/contracts/src/wallet/v5r1/mod.rs @@ -5,7 +5,7 @@ use lazy_static::lazy_static; use nacl::sign::PUBLIC_KEY_LENGTH; use tlb::{ bits::{de::BitReaderExt, ser::BitWriterExt}, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{Data, NoArgs}, ser::{CellBuilder, CellBuilderError, CellSerialize}, Cell, Error, ResultExt, @@ -105,7 +105,7 @@ impl CellSerialize for WalletV5R1Data { impl<'de> CellDeserialize<'de> for WalletV5R1Data { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { is_signature_allowed: parser.unpack()?, seqno: parser.unpack()?, @@ -141,7 +141,7 @@ impl CellSerialize for WalletV5R1InnerRequest { } impl<'de> CellDeserialize<'de> for WalletV5R1InnerRequest { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { out_actions: parser .parse_as::<_, Option>() @@ -200,7 +200,7 @@ impl CellSerialize for ExtendedAction { } impl<'de> CellDeserialize<'de> for ExtendedAction { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(match parser.unpack()? { Self::ADD_EXTENSION_PREFIX => Self::AddExtension(parser.unpack()?), Self::DELETE_EXTENSION_PREFIX => Self::DeleteExtension(parser.unpack()?), @@ -241,7 +241,7 @@ impl CellSerialize for WalletV5RSignBody { } impl<'de> CellDeserialize<'de> for WalletV5RSignBody { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { wallet_id: parser.unpack()?, valid_until: parser.unpack_as::<_, UnixTimestamp>()?, @@ -274,7 +274,7 @@ impl CellSerialize for WalletV5R1SignedRequest { } impl<'de> CellDeserialize<'de> for WalletV5R1SignedRequest { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { body: parser.parse()?, signature: parser.unpack()?, @@ -320,7 +320,7 @@ impl CellSerialize for WalletV5R1MsgBody { } impl<'de> CellDeserialize<'de> for WalletV5R1MsgBody { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(match parser.unpack()? { Self::INTERNAL_SIGNED_PREFIX => { Self::InternalSigned(parser.parse().context("internal_signed")?) @@ -350,7 +350,7 @@ impl CellSerialize for InternalExtensionWalletV5R1MsgBody { } impl<'de> CellDeserialize<'de> for InternalExtensionWalletV5R1MsgBody { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { query_id: parser.unpack()?, inner: parser.parse()?, diff --git a/crates/tlb-ton/src/action.rs b/crates/tlb-ton/src/action.rs index ee2b575..905bfe0 100644 --- a/crates/tlb-ton/src/action.rs +++ b/crates/tlb-ton/src/action.rs @@ -1,6 +1,6 @@ use tlb::{ bits::{de::BitReaderExt, r#as::NBits, ser::BitWriterExt}, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, r#as::Ref, ser::{CellBuilder, CellBuilderError, CellSerialize}, Cell, Error, ResultExt, @@ -59,7 +59,7 @@ impl CellSerialize for OutAction { impl<'de> CellDeserialize<'de> for OutAction { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(match parser.unpack()? { Self::SEND_MSG_PREFIX => Self::SendMsg(parser.parse().context("action_send_msg")?), Self::SET_CODE_PREFIX => { @@ -106,7 +106,7 @@ where ID: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { mode: parser.unpack()?, message: parser.parse_as::<_, Ref>()?, @@ -133,7 +133,7 @@ impl CellSerialize for ReserveCurrencyAction { impl<'de> CellDeserialize<'de> for ReserveCurrencyAction { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { mode: parser.unpack()?, currency: parser.parse()?, @@ -168,7 +168,7 @@ where R: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { mode: parser.unpack_as::<_, NBits<7>>()?, libref: parser.parse()?, diff --git a/crates/tlb-ton/src/bin_tree/aug.rs b/crates/tlb-ton/src/bin_tree/aug.rs index bd69241..6daf72a 100644 --- a/crates/tlb-ton/src/bin_tree/aug.rs +++ b/crates/tlb-ton/src/bin_tree/aug.rs @@ -1,6 +1,6 @@ use tlb::{ bits::{de::BitReaderExt, ser::BitWriterExt}, - de::{args::r#as::CellDeserializeAsWithArgs, CellParser, CellParserError}, + de::{args::r#as::CellDeserializeAsWithArgs, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{ParseFully, Ref}, ser::{args::r#as::CellSerializeAsWithArgs, CellBuilder, CellBuilderError}, }; @@ -49,9 +49,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(BinTreeAug { extra: parser.parse_as_with::<_, AsE>(extra_args.clone())?, node: parser @@ -113,9 +113,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(match parser.unpack()? { false => BinTreeNode::Leaf(parser.parse_as_with::<_, AsT>(args)?), true => BinTreeNode::Fork( diff --git a/crates/tlb-ton/src/bin_tree/mod.rs b/crates/tlb-ton/src/bin_tree/mod.rs index fc42f49..33db9d9 100644 --- a/crates/tlb-ton/src/bin_tree/mod.rs +++ b/crates/tlb-ton/src/bin_tree/mod.rs @@ -5,7 +5,7 @@ use std::ops::Deref; use tlb::bits::de::BitReaderExt; use tlb::de::args::r#as::CellDeserializeAsWithArgs; -use tlb::de::{CellParser, CellParserError}; +use tlb::de::{OrdinaryCellParser, OrdinaryCellParserError}; use tlb::r#as::Ref; /// [`BinTree X`](https://docs.ton.org/develop/data-formats/tl-b-types#bintree) @@ -62,9 +62,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(match parser.unpack()? { // bt_leaf$0 false => BinTree::Leaf(parser.parse_as_with::(args)?), @@ -83,19 +83,19 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { let mut output = Vec::new(); - let mut stack: Vec> = Vec::new(); + let mut stack: Vec> = Vec::new(); #[inline] fn parse<'de, T, As>( - parser: &mut CellParser<'de>, - stack: &mut Vec>, + parser: &mut OrdinaryCellParser<'de>, + stack: &mut Vec>, output: &mut Vec, args: As::Args, - ) -> Result<(), CellParserError<'de>> + ) -> Result<(), OrdinaryCellParserError<'de>> where As: CellDeserializeAsWithArgs<'de, T>, { diff --git a/crates/tlb-ton/src/currency.rs b/crates/tlb-ton/src/currency.rs index 69a7670..2a55daf 100644 --- a/crates/tlb-ton/src/currency.rs +++ b/crates/tlb-ton/src/currency.rs @@ -4,7 +4,7 @@ use num_bigint::BigUint; use num_traits::One; use tlb::{ bits::{de::BitReaderExt, r#as::VarInt, ser::BitWriterExt}, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{Data, NoArgs}, ser::{CellBuilder, CellBuilderError, CellSerialize}, }; @@ -52,7 +52,7 @@ impl CellSerialize for CurrencyCollection { impl<'de> CellDeserialize<'de> for CurrencyCollection { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { grams: parser.unpack_as::<_, Grams>()?, other: parser.parse()?, @@ -79,7 +79,7 @@ impl CellSerialize for ExtraCurrencyCollection { impl<'de> CellDeserialize<'de> for ExtraCurrencyCollection { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self( parser.parse_as_with::<_, HashmapE>>, NoArgs<_>>>(( 32, diff --git a/crates/tlb-ton/src/hashmap/aug.rs b/crates/tlb-ton/src/hashmap/aug.rs index 5e93db2..51fdd71 100644 --- a/crates/tlb-ton/src/hashmap/aug.rs +++ b/crates/tlb-ton/src/hashmap/aug.rs @@ -9,7 +9,7 @@ use tlb::{ }, de::{ args::{r#as::CellDeserializeAsWithArgs, CellDeserializeWithArgs}, - CellParser, CellParserError, + OrdinaryCellParser, OrdinaryCellParserError, }, r#as::{ParseFully, Ref, Same}, ser::{ @@ -75,9 +75,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, node_args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(HashmapAugE { m: parser.parse_as_with::<_, HashmapE>((n, node_args, extra_args.clone()))?, // extra:Y @@ -221,9 +221,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, node_args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(match parser.unpack()? { // hme_empty$0 false => HashmapE::Empty, @@ -246,9 +246,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_as_with::<_, Same>(args) } } @@ -264,9 +264,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, node_args): Self::Args, - ) -> Result> { + ) -> Result> { Ok(match parser.unpack()? { // hme_empty$0 false => C::default(), @@ -375,9 +375,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, node_args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { // label:(HmLabel ~l n) let prefix: BitVec = parser.unpack_as_with::<_, HmLabel>(n).context("label")?; // {n = (~m) + l} @@ -404,21 +404,21 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, args): Self::Args, - ) -> Result> { + ) -> Result> { let mut output = C::default(); - let mut stack: Vec<(u32, Key, CellParser<'de>)> = Vec::new(); + let mut stack: Vec<(u32, Key, OrdinaryCellParser<'de>)> = Vec::new(); #[inline] fn parse<'de, T, As, C>( - parser: &mut CellParser<'de>, - stack: &mut Vec<(u32, Key, CellParser<'de>)>, + parser: &mut OrdinaryCellParser<'de>, + stack: &mut Vec<(u32, Key, OrdinaryCellParser<'de>)>, output: &mut C, n: u32, mut prefix: Key, args: As::Args, - ) -> Result<(), CellParserError<'de>> + ) -> Result<(), OrdinaryCellParserError<'de>> where C: Extend<(Key, T)>, As: CellDeserializeAsWithArgs<'de, T>, @@ -599,9 +599,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, node_args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { if n == 0 { // hmn_leaf#_ {X:Type} value:X = HashmapNode 0 X; return parser @@ -678,9 +678,9 @@ where type Args = (u32, AsT::Args, AsE::Args); fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, node_args, extra_args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(HashmapAugNode { // extra:Y extra: parser.parse_as_with::<_, AsE>(extra_args.clone())?, diff --git a/crates/tlb-ton/src/hashmap/pfx.rs b/crates/tlb-ton/src/hashmap/pfx.rs index 201bcbf..5472e5c 100644 --- a/crates/tlb-ton/src/hashmap/pfx.rs +++ b/crates/tlb-ton/src/hashmap/pfx.rs @@ -6,7 +6,7 @@ use tlb::{ de::BitReaderExt, ser::BitWriterExt, }, - de::{args::r#as::CellDeserializeAsWithArgs, CellParser, CellParserError}, + de::{args::r#as::CellDeserializeAsWithArgs, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{ParseFully, Ref, Same}, ser::{args::r#as::CellSerializeAsWithArgs, CellBuilder, CellBuilderError}, Error, ResultExt, @@ -59,9 +59,9 @@ where #[inline] fn parse_as_with( - parser: &mut tlb::de::CellParser<'de>, + parser: &mut tlb::de::OrdinaryCellParser<'de>, (n, args): Self::Args, - ) -> Result, tlb::de::CellParserError<'de>> { + ) -> Result, tlb::de::OrdinaryCellParserError<'de>> { Ok(match parser.unpack()? { // hme_empty$0 false => HashmapE::Empty, @@ -122,9 +122,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { // label:(HmLabel ~l n) let prefix: BitVec = parser.unpack_as_with::<_, HmLabel>(n).context("label")?; // {n = (~m) + l} @@ -194,9 +194,9 @@ where type Args = (u32, As::Args); fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (n, args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { match parser.unpack()? { // phmn_leaf$0 false => { diff --git a/crates/tlb-ton/src/library.rs b/crates/tlb-ton/src/library.rs index ca84063..a76fdba 100644 --- a/crates/tlb-ton/src/library.rs +++ b/crates/tlb-ton/src/library.rs @@ -1,5 +1,5 @@ use tlb::{ - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, either::Either, r#as::{Data, Ref}, ser::{CellBuilder, CellBuilderError, CellSerialize}, @@ -35,7 +35,7 @@ where R: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(match parser.parse_as::<_, Either>()? { Either::Left(hash) => Self::Hash(hash), Either::Right(library) => Self::Ref(library), diff --git a/crates/tlb-ton/src/list.rs b/crates/tlb-ton/src/list.rs index dc8c155..a6c3314 100644 --- a/crates/tlb-ton/src/list.rs +++ b/crates/tlb-ton/src/list.rs @@ -1,7 +1,7 @@ use core::marker::PhantomData; use tlb::{ - de::{r#as::CellDeserializeAs, CellParser, CellParserError}, + de::{r#as::CellDeserializeAs, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{Ref, Same}, ser::{r#as::CellSerializeAs, CellBuilder, CellBuilderError}, Cell, ResultExt, @@ -34,9 +34,9 @@ where As: CellDeserializeAs<'de, T>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { let mut v = Vec::new(); - let mut p: CellParser<'de> = parser.parse()?; + let mut p: OrdinaryCellParser<'de> = parser.parse()?; while !p.no_references_left() { v.push( p.parse_as::<_, As>() diff --git a/crates/tlb-ton/src/message.rs b/crates/tlb-ton/src/message.rs index 13d5c0a..b7e30d6 100644 --- a/crates/tlb-ton/src/message.rs +++ b/crates/tlb-ton/src/message.rs @@ -7,7 +7,7 @@ use tlb::{ r#as::NBits, ser::{BitPack, BitWriter, BitWriterExt}, }, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{DefaultOnNone, EitherInlineOrRef}, ser::{CellBuilder, CellBuilderError, CellSerialize, CellSerializeExt}, Cell, ResultExt, @@ -91,7 +91,7 @@ where IC: CellDeserialize<'de>, ID: CellDeserialize<'de>, { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { // info:CommonMsgInfo info: parser.parse().context("info")?, @@ -154,7 +154,7 @@ impl CellSerialize for CommonMsgInfo { impl<'de> CellDeserialize<'de> for CommonMsgInfo { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { match parser.unpack()? { // int_msg_info$0 false => Ok(Self::Internal(parser.parse().context("int_msg_info")?)), @@ -243,7 +243,7 @@ impl CellSerialize for InternalMsgInfo { } impl<'de> CellDeserialize<'de> for InternalMsgInfo { - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { ihr_disabled: parser.unpack()?, bounce: parser.unpack()?, diff --git a/crates/tlb-ton/src/state_init.rs b/crates/tlb-ton/src/state_init.rs index c25fb8f..bbf696a 100644 --- a/crates/tlb-ton/src/state_init.rs +++ b/crates/tlb-ton/src/state_init.rs @@ -6,7 +6,7 @@ use tlb::{ r#as::NBits, ser::{BitPack, BitWriter, BitWriterExt}, }, - de::{CellDeserialize, CellParser, CellParserError}, + de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, r#as::{NoArgs, ParseFully, Ref}, ser::{CellBuilder, CellBuilderError, CellSerialize, CellSerializeExt}, Cell, @@ -83,7 +83,7 @@ where D: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { // split_depth:(Maybe (## 5)) split_depth: parser.unpack_as::<_, Option>>()?, @@ -153,7 +153,7 @@ impl CellSerialize for SimpleLib { impl<'de> CellDeserialize<'de> for SimpleLib { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(SimpleLib { public: parser.unpack()?, root: parser.parse_as::<_, Ref>()?, diff --git a/crates/tlb/src/as/args.rs b/crates/tlb/src/as/args.rs index 0a8a853..5ee635a 100644 --- a/crates/tlb/src/as/args.rs +++ b/crates/tlb/src/as/args.rs @@ -1,6 +1,6 @@ use crate::{ de::{ - args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, CellParser, CellParserError, + args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, OrdinaryCellParser, OrdinaryCellParserError, }, ser::{ args::r#as::CellSerializeAsWithArgs, r#as::CellSerializeAs, CellBuilder, CellBuilderError, @@ -33,9 +33,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, _args: Self::Args, - ) -> Result> { + ) -> Result> { As::parse_as(parser) } } @@ -57,7 +57,7 @@ where As::Args: Default, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::parse_as_with(parser, ::default()) } } diff --git a/crates/tlb/src/as/data.rs b/crates/tlb/src/as/data.rs index ea0599d..e002351 100644 --- a/crates/tlb/src/as/data.rs +++ b/crates/tlb/src/as/data.rs @@ -5,7 +5,7 @@ use tlbits::{de::args::r#as::BitUnpackAsWithArgs, ser::args::r#as::BitPackAsWith use crate::{ bits::{de::r#as::BitUnpackAs, ser::r#as::BitPackAs}, de::{ - args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, CellParser, CellParserError, + args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, OrdinaryCellParser, OrdinaryCellParserError, }, ser::{ args::r#as::CellSerializeAsWithArgs, r#as::CellSerializeAs, CellBuilder, CellBuilderError, @@ -99,7 +99,7 @@ where As: BitUnpackAs + ?Sized, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::unpack_as(parser) } } @@ -112,9 +112,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { As::unpack_as_with(parser, args) } } diff --git a/crates/tlb/src/as/default.rs b/crates/tlb/src/as/default.rs index 4478d44..26e6dac 100644 --- a/crates/tlb/src/as/default.rs +++ b/crates/tlb/src/as/default.rs @@ -1,5 +1,5 @@ use crate::{ - de::{r#as::CellDeserializeAs, CellParser, CellParserError}, + de::{r#as::CellDeserializeAs, OrdinaryCellParser, OrdinaryCellParserError}, ser::{r#as::CellSerializeAs, CellBuilder, CellBuilderError}, }; @@ -25,7 +25,7 @@ where As: CellDeserializeAs<'de, T>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser .parse_as::<_, Option>() .map(Option::unwrap_or_default) diff --git a/crates/tlb/src/as/from_into.rs b/crates/tlb/src/as/from_into.rs index e64d062..bd7d6a1 100644 --- a/crates/tlb/src/as/from_into.rs +++ b/crates/tlb/src/as/from_into.rs @@ -4,7 +4,7 @@ use crate::{ de::{ args::{r#as::CellDeserializeAsWithArgs, CellDeserializeWithArgs}, r#as::CellDeserializeAs, - CellDeserialize, CellParser, CellParserError, + CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError, }, ser::{ args::{r#as::CellSerializeAsWithArgs, CellSerializeWithArgs}, @@ -49,7 +49,7 @@ where As: Into + CellDeserialize<'de>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::parse(parser).map(Into::into) } } @@ -62,9 +62,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { As::parse_with(parser, args).map(Into::into) } } @@ -102,7 +102,7 @@ where As: Into + CellDeserialize<'de>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::parse(parser).map(Into::into) } } @@ -115,9 +115,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { As::parse_with(parser, args).map(Into::into) } } @@ -166,7 +166,7 @@ where >::Error: Display, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::parse(parser)?.try_into().map_err(Error::custom) } } @@ -180,9 +180,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { As::parse_with(parser, args)? .try_into() .map_err(Error::custom) @@ -229,7 +229,7 @@ where >::Error: Display, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::parse(parser)?.try_into().map_err(Error::custom) } } @@ -243,9 +243,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { As::parse_with(parser, args)? .try_into() .map_err(Error::custom) diff --git a/crates/tlb/src/as/fully.rs b/crates/tlb/src/as/fully.rs index 6f5ade7..55f13ed 100644 --- a/crates/tlb/src/as/fully.rs +++ b/crates/tlb/src/as/fully.rs @@ -1,7 +1,7 @@ use core::marker::PhantomData; use crate::de::{ - args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, CellParser, CellParserError, + args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, OrdinaryCellParser, OrdinaryCellParserError, }; use super::Same; @@ -15,7 +15,7 @@ where As: CellDeserializeAs<'de, T> + ?Sized, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { let v = parser.parse_as::<_, As>()?; parser.ensure_empty()?; Ok(v) @@ -30,9 +30,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { let v = parser.parse_as_with::<_, As>(args)?; parser.ensure_empty()?; Ok(v) diff --git a/crates/tlb/src/as/mod.rs b/crates/tlb/src/as/mod.rs index d21f43f..d57661c 100644 --- a/crates/tlb/src/as/mod.rs +++ b/crates/tlb/src/as/mod.rs @@ -18,7 +18,7 @@ use crate::{ de::{ args::{r#as::CellDeserializeAsWithArgs, CellDeserializeWithArgs}, r#as::CellDeserializeAs, - CellDeserialize, CellParser, CellParserError, + CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError, }, ser::{ args::{r#as::CellSerializeAsWithArgs, CellSerializeWithArgs}, @@ -63,7 +63,7 @@ where As: CellDeserializeAs<'de, T> + ?Sized, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { As::parse_as(parser).map(Self::new) } } @@ -75,9 +75,9 @@ where type Args = As::Args; fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { As::parse_as_with(parser, args).map(Self::new) } } diff --git a/crates/tlb/src/as/reference.rs b/crates/tlb/src/as/reference.rs index 74198b8..625b280 100644 --- a/crates/tlb/src/as/reference.rs +++ b/crates/tlb/src/as/reference.rs @@ -4,7 +4,7 @@ use tlbits::{either::Either, r#as::args::NoArgs, ser::BitWriter}; use crate::{ de::{ - args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, CellParser, CellParserError, + args::r#as::CellDeserializeAsWithArgs, r#as::CellDeserializeAs, OrdinaryCellParser, OrdinaryCellParserError, }, ser::{ args::r#as::CellSerializeAsWithArgs, r#as::CellSerializeAs, CellBuilder, CellBuilderError, @@ -51,7 +51,7 @@ where As: CellDeserializeAs<'de, T> + ?Sized, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.parse_reference_as::().context("^") } } @@ -64,9 +64,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_reference_as_with::(args).context("^") } } @@ -117,7 +117,7 @@ where As: CellDeserializeAs<'de, T>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { EitherInlineOrRef::>::parse_as_with(parser, ()) } } @@ -130,9 +130,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { Either::>::parse_as_with(parser, args).map(Either::into_inner) } } diff --git a/crates/tlb/src/as/same.rs b/crates/tlb/src/as/same.rs index b379c65..f8634bd 100644 --- a/crates/tlb/src/as/same.rs +++ b/crates/tlb/src/as/same.rs @@ -2,7 +2,7 @@ use crate::{ de::{ args::{r#as::CellDeserializeAsWithArgs, CellDeserializeWithArgs}, r#as::CellDeserializeAs, - CellDeserialize, CellParser, CellParserError, + CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError, }, ser::{ args::{r#as::CellSerializeAsWithArgs, CellSerializeWithArgs}, @@ -44,7 +44,7 @@ where T: CellDeserialize<'de>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result> { T::parse(parser) } } @@ -57,9 +57,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { T::parse_with(parser, args) } } diff --git a/crates/tlb/src/cell/mod.rs b/crates/tlb/src/cell/mod.rs index 1089652..0c8329a 100644 --- a/crates/tlb/src/cell/mod.rs +++ b/crates/tlb/src/cell/mod.rs @@ -27,7 +27,7 @@ use crate::{ de::{ args::{r#as::CellDeserializeAsWithArgs, CellDeserializeWithArgs}, r#as::CellDeserializeAs, - CellDeserialize, CellParser, CellParserError, + CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError, }, ser::CellBuilder, }; @@ -211,21 +211,20 @@ impl Cell { self.higher_hash(0) } - /// Return [`CellParser`] for this cell + /// Return [`OrdinaryCellParser`] for this cell #[inline] #[must_use] - pub fn parser(&self) -> CellParser<'_> { - CellParser::new( - self.as_type(), + pub fn parser(&self) -> OrdinaryCellParser<'_> { + OrdinaryCellParser::new( self.level(), self.as_bitslice(), self.references(), ) } - /// Shortcut for [`.parser()`](Cell::parser)[`.parse()`](CellParser::parse)[`.ensure_empty()`](CellParser::ensure_empty). + /// Shortcut for [`.parser()`](Cell::parser)[`.parse()`](OrdinaryCellParser::parse)[`.ensure_empty()`](OrdinaryCellParser::ensure_empty). #[inline] - pub fn parse_fully<'de, T>(&'de self) -> Result> + pub fn parse_fully<'de, T>(&'de self) -> Result> where T: CellDeserialize<'de>, { @@ -235,9 +234,9 @@ impl Cell { Ok(v) } - /// Shortcut for [`.parser()`](Cell::parser)[`.parse_with()`](CellParser::parse_with)[`.ensure_empty()`](CellParser::ensure_empty). + /// Shortcut for [`.parser()`](Cell::parser)[`.parse_with()`](OrdinaryCellParser::parse_with)[`.ensure_empty()`](OrdinaryCellParser::ensure_empty). #[inline] - pub fn parse_fully_with<'de, T>(&'de self, args: T::Args) -> Result> + pub fn parse_fully_with<'de, T>(&'de self, args: T::Args) -> Result> where T: CellDeserializeWithArgs<'de>, { @@ -247,9 +246,9 @@ impl Cell { Ok(v) } - /// Shortcut for [`.parser()`](Cell::parser)[`.parse_as()`](CellParser::parse_as)[`.ensure_empty()`](CellParser::ensure_empty). + /// Shortcut for [`.parser()`](Cell::parser)[`.parse_as()`](OrdinaryCellParser::parse_as)[`.ensure_empty()`](OrdinaryCellParser::ensure_empty). #[inline] - pub fn parse_fully_as<'de, T, As>(&'de self) -> Result> + pub fn parse_fully_as<'de, T, As>(&'de self) -> Result> where As: CellDeserializeAs<'de, T> + ?Sized, { @@ -259,12 +258,12 @@ impl Cell { Ok(v) } - /// Shortcut for [`.parser()`](Cell::parser)[`.parse_as_with()`](CellParser::parse_as_with)[`.ensure_empty()`](CellParser::ensure_empty). + /// Shortcut for [`.parser()`](Cell::parser)[`.parse_as_with()`](OrdinaryCellParser::parse_as_with)[`.ensure_empty()`](OrdinaryCellParser::ensure_empty). #[inline] pub fn parse_fully_as_with<'de, T, As>( &'de self, args: As::Args, - ) -> Result> + ) -> Result> where As: CellDeserializeAsWithArgs<'de, T> + ?Sized, { diff --git a/crates/tlb/src/de/args/as.rs b/crates/tlb/src/de/args/as.rs index d48de12..e17a789 100644 --- a/crates/tlb/src/de/args/as.rs +++ b/crates/tlb/src/de/args/as.rs @@ -8,7 +8,7 @@ use crate::{ }; use super::{ - super::{CellParser, CellParserError}, + super::{OrdinaryCellParser, OrdinaryCellParserError}, CellDeserializeWithArgs, }; @@ -22,9 +22,9 @@ pub trait CellDeserializeAsWithArgs<'de, T> { /// Parse value with args using an adapter fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result>; + ) -> Result>; } /// Owned version of [`CellDeserializeAsWithArgs`] @@ -43,9 +43,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result<[T; N], CellParserError<'de>> { + ) -> Result<[T; N], OrdinaryCellParserError<'de>> { let mut arr: [MaybeUninit; N] = unsafe { MaybeUninit::uninit().assume_init() }; for a in &mut arr { a.write(parser.parse_as_with::(args.clone())?); @@ -63,9 +63,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (len, args): Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { parser.parse_iter_as_with::<_, As>(args).take(len).collect() } } @@ -80,7 +80,7 @@ macro_rules! impl_cell_deserialize_as_with_args_for_tuple { type Args = ($($a::Args,)+); #[inline] - fn parse_as_with(parser: &mut CellParser<'de>, args: Self::Args) -> Result<($($t,)+), CellParserError<'de>> + fn parse_as_with(parser: &mut OrdinaryCellParser<'de>, args: Self::Args) -> Result<($($t,)+), OrdinaryCellParserError<'de>> { Ok(($( $a::parse_as_with(parser, args.$n) @@ -109,9 +109,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { AsWrap::::parse_with(parser, args) .map(AsWrap::into_inner) .map(Into::into) @@ -126,9 +126,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { AsWrap::::parse_with(parser, args) .map(AsWrap::into_inner) .map(Into::into) @@ -143,9 +143,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { AsWrap::::parse_with(parser, args) .map(AsWrap::into_inner) .map(Into::into) @@ -167,9 +167,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok( Either::, AsWrap>::parse_with(parser, args)? .map_either(AsWrap::into_inner, AsWrap::into_inner), @@ -185,9 +185,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(parser .parse_as_with::, Either, As>>(args)? .right()) @@ -207,9 +207,9 @@ where #[inline] fn parse_as_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result, CellParserError<'de>> { + ) -> Result, OrdinaryCellParserError<'de>> { Ok(Option::>::parse_with(parser, args)?.map(AsWrap::into_inner)) } } diff --git a/crates/tlb/src/de/args/mod.rs b/crates/tlb/src/de/args/mod.rs index 8557284..8d55030 100644 --- a/crates/tlb/src/de/args/mod.rs +++ b/crates/tlb/src/de/args/mod.rs @@ -9,7 +9,7 @@ use crate::{ ResultExt, }; -use super::{CellParser, CellParserError}; +use super::{OrdinaryCellParser, OrdinaryCellParserError}; /// A type that can be **de**serialized. /// In contrast with [`CellDeserialize`](super::CellDeserialize) it allows to @@ -20,9 +20,9 @@ pub trait CellDeserializeWithArgs<'de>: Sized { /// Parses the value with args fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result>; + ) -> Result>; } /// Owned version of [`CellDeserializeWithArgs`] @@ -37,9 +37,9 @@ where type Args = T::Args; fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { let mut arr: [MaybeUninit; N] = unsafe { MaybeUninit::uninit().assume_init() }; for (i, a) in arr.iter_mut().enumerate() { a.write(T::parse_with(parser, args.clone()).with_context(|| format!("[{i}]"))?); @@ -58,7 +58,7 @@ macro_rules! impl_cell_deserialize_with_args_for_tuple { type Args = ($($t::Args,)+); #[inline] - fn parse_with(parser: &mut CellParser<'de>, args: Self::Args) -> Result> + fn parse_with(parser: &mut OrdinaryCellParser<'de>, args: Self::Args) -> Result> { Ok(($( $t::parse_with(parser, args.$n).context(concat!(".", stringify!($n)))?, @@ -87,9 +87,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, (len, args): Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_iter_with(args).take(len).collect() } } @@ -102,9 +102,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_as_with::<_, FromInto>(args) } } @@ -117,9 +117,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_as_with::<_, FromInto>(args) } } @@ -132,9 +132,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_as_with::<_, FromInto>(args) } } @@ -153,9 +153,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { match parser.unpack().context("tag")? { false => parser.parse_with(args).map(Either::Left).context("left"), true => parser.parse_with(args).map(Either::Right).context("right"), @@ -176,9 +176,9 @@ where #[inline] fn parse_with( - parser: &mut CellParser<'de>, + parser: &mut OrdinaryCellParser<'de>, args: Self::Args, - ) -> Result> { + ) -> Result> { parser.parse_as_with::<_, Either<(), Same>>(args) } } diff --git a/crates/tlb/src/de/as.rs b/crates/tlb/src/de/as.rs index 5d7369e..604d0cd 100644 --- a/crates/tlb/src/de/as.rs +++ b/crates/tlb/src/de/as.rs @@ -3,7 +3,7 @@ use std::{rc::Rc, sync::Arc}; use crate::{either::Either, r#as::AsWrap, ResultExt}; -use super::{CellDeserialize, CellParser, CellParserError}; +use super::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}; /// Adapter to **de**serialize `T`. /// See [`as`](crate::as) module-level documentation for more. @@ -11,7 +11,7 @@ use super::{CellDeserialize, CellParser, CellParserError}; /// For dynamic arguments, see /// [`CellDeserializeAsWithArgs`](super::args::as::CellDeserializeAsWithArgs). pub trait CellDeserializeAs<'de, T> { - fn parse_as(parser: &mut CellParser<'de>) -> Result>; + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result>; } /// Owned version of [`CellDeserializeAs`] @@ -23,7 +23,7 @@ where As: CellDeserializeAs<'de, T>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result<[T; N], CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result<[T; N], OrdinaryCellParserError<'de>> { let mut arr: [MaybeUninit; N] = unsafe { MaybeUninit::uninit().assume_init() }; for a in &mut arr { a.write(parser.parse_as::()?); @@ -40,7 +40,7 @@ macro_rules! impl_cell_deserialize_as_for_tuple { )+ { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result<($($t,)+), CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result<($($t,)+), OrdinaryCellParserError<'de>> { Ok(($( AsWrap::<$t, $a>::parse(parser) .context(concat!(".", stringify!($n)))? @@ -66,7 +66,7 @@ where As: CellDeserializeAs<'de, T> + ?Sized, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { AsWrap::::parse(parser) .map(AsWrap::into_inner) .map(Box::new) @@ -78,7 +78,7 @@ where As: CellDeserializeAs<'de, T> + ?Sized, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { AsWrap::::parse(parser) .map(AsWrap::into_inner) .map(Rc::new) @@ -90,7 +90,7 @@ where As: CellDeserializeAs<'de, T> + ?Sized, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { AsWrap::::parse(parser) .map(AsWrap::into_inner) .map(Arc::new) @@ -109,7 +109,7 @@ where AsRight: CellDeserializeAs<'de, Right>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { Ok( Either::, AsWrap>::parse(parser)? .map_either(AsWrap::into_inner, AsWrap::into_inner), @@ -122,7 +122,7 @@ where As: CellDeserializeAs<'de, T>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { Ok(Either::<(), AsWrap>::parse(parser)? .map_right(AsWrap::into_inner) .right()) @@ -139,7 +139,7 @@ where As: CellDeserializeAs<'de, T>, { #[inline] - fn parse_as(parser: &mut CellParser<'de>) -> Result, CellParserError<'de>> { + fn parse_as(parser: &mut OrdinaryCellParser<'de>) -> Result, OrdinaryCellParserError<'de>> { Ok(Option::>::parse(parser)?.map(AsWrap::into_inner)) } } diff --git a/crates/tlb/src/de/mod.rs b/crates/tlb/src/de/mod.rs index 4b279ef..5bac94f 100644 --- a/crates/tlb/src/de/mod.rs +++ b/crates/tlb/src/de/mod.rs @@ -8,32 +8,36 @@ pub use self::parser::*; use core::mem::MaybeUninit; use std::{mem, rc::Rc, sync::Arc}; -use crate::cell_type::CellType; -use crate::{bits::de::BitReaderExt, either::Either, r#as::{FromInto, Same}, Cell, LibraryReferenceCell, MerkleProofCell, MerkleUpdateCell, OrdinaryCell, PrunedBranchCell, ResultExt}; - -/// A type that can be **de**serialized from [`CellParser`]. -pub trait CellDeserialize<'de>: Sized { +use crate::{ + bits::de::BitReaderExt, + either::Either, + r#as::{FromInto, Same}, + Cell, OrdinaryCell, ResultExt, +}; + +/// A type that can be **de**serialized from [`OrdinaryCellParser`]. +pub trait CellDeserialize<'de, C = OrdinaryCell>: Sized { /// Parse value - fn parse(parser: &mut CellParser<'de>) -> Result>; + fn parse(parser: &mut CellParser<'de, C>) -> Result>; } /// Owned version of [`CellDeserialize`] -pub trait CellDeserializeOwned: for<'de> CellDeserialize<'de> {} -impl CellDeserializeOwned for T where T: for<'de> CellDeserialize<'de> {} +pub trait CellDeserializeOwned: for<'de> CellDeserialize<'de, C> {} +impl CellDeserializeOwned for T where T: for<'de> CellDeserialize<'de, C> {} -impl<'de> CellDeserialize<'de> for () { +impl<'de, C> CellDeserialize<'de, C> for () { #[inline] - fn parse(_parser: &mut CellParser<'de>) -> Result> { + fn parse(_parser: &mut CellParser<'de, C>) -> Result> { Ok(()) } } -impl<'de, T, const N: usize> CellDeserialize<'de> for [T; N] +impl<'de, C, T, const N: usize> CellDeserialize<'de, C> for [T; N] where - T: CellDeserialize<'de>, + T: CellDeserialize<'de, C>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut CellParser<'de, C>) -> Result> { let mut arr: [MaybeUninit; N] = unsafe { MaybeUninit::uninit().assume_init() }; for a in &mut arr { a.write(T::parse(parser)?); @@ -44,13 +48,13 @@ where macro_rules! impl_cell_deserialize_for_tuple { ($($n:tt:$t:ident),+) => { - impl<'de, $($t),+> CellDeserialize<'de> for ($($t,)+) + impl<'de, C, $($t),+> CellDeserialize<'de, C> for ($($t,)+) where $( - $t: CellDeserialize<'de>, + $t: CellDeserialize<'de, C>, )+ { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> + fn parse(parser: &mut CellParser<'de, C>) -> Result> { Ok(($( $t::parse(parser).context(concat!(".", stringify!($n)))?, @@ -75,7 +79,7 @@ where T: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.parse_as::<_, FromInto>() } } @@ -85,7 +89,7 @@ where T: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.parse_as::<_, FromInto>() } } @@ -95,7 +99,7 @@ where T: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.parse_as::<_, FromInto>() } } @@ -111,7 +115,7 @@ where Right: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { match parser.unpack().context("tag")? { false => parser.parse().map(Either::Left).context("left"), true => parser.parse().map(Either::Right).context("right"), @@ -129,34 +133,18 @@ where T: CellDeserialize<'de>, { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { parser.parse_as::<_, Either<(), Same>>() } } impl<'de> CellDeserialize<'de> for Cell { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { - let cell = match parser.r#type { - CellType::Ordinary => Cell::Ordinary(OrdinaryCell { - data: mem::take(&mut parser.data).to_bitvec(), - references: mem::take(&mut parser.references).to_vec(), - }), - CellType::LibraryReference => Cell::LibraryReference(LibraryReferenceCell { - data: mem::take(&mut parser.data).to_bitvec(), - }), - CellType::PrunedBranch => Cell::PrunedBranch(PrunedBranchCell { - data: mem::take(&mut parser.data).to_bitvec(), - }), - CellType::MerkleProof => Cell::MerkleProof(MerkleProofCell { - data: mem::take(&mut parser.data).to_bitvec(), - references: mem::take(&mut parser.references).to_vec(), - }), - CellType::MerkleUpdate => Cell::MerkleUpdate(MerkleUpdateCell { - data: mem::take(&mut parser.data).to_bitvec(), - references: mem::take(&mut parser.references).to_vec(), - }) - }; + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { + let cell = Cell::Ordinary(OrdinaryCell { + data: mem::take(&mut parser.data).to_bitvec(), + references: mem::take(&mut parser.references).to_vec(), + }); parser.ensure_empty()?; diff --git a/crates/tlb/src/de/parser.rs b/crates/tlb/src/de/parser.rs index 3e4a7fb..de5ac56 100644 --- a/crates/tlb/src/de/parser.rs +++ b/crates/tlb/src/de/parser.rs @@ -1,16 +1,13 @@ use core::{iter, mem}; +use std::marker::PhantomData; use std::sync::Arc; use tlbits::ResultExt; -use crate::cell_type::CellType; -use crate::{ - bits::{ - bitvec::{order::Msb0, slice::BitSlice}, - de::BitReader, - }, - Cell, Error, -}; +use crate::{bits::{ + bitvec::{order::Msb0, slice::BitSlice}, + de::BitReader, +}, Cell, Error, OrdinaryCell}; use super::{ args::{r#as::CellDeserializeAsWithArgs, CellDeserializeWithArgs}, @@ -18,28 +15,30 @@ use super::{ CellDeserialize, }; -/// [`Error`] for [`CellParser`] -pub type CellParserError<'de> = as BitReader>::Error; +/// [`Error`] for [`OrdinaryCellParser`] +pub type OrdinaryCellParserError<'de> = as BitReader>::Error; +pub type CellParserError<'de, C> = as BitReader>::Error; /// Cell parser created with [`Cell::parser()`]. #[derive(Clone)] -pub struct CellParser<'de> { - pub(crate) r#type: CellType, +pub struct CellParser<'de, T> { + _type: PhantomData, pub(crate) level: u8, pub(crate) data: &'de BitSlice, pub(crate) references: &'de [Arc], } -impl<'de> CellParser<'de> { +pub type OrdinaryCellParser<'de> = CellParser<'de, OrdinaryCell>; + +impl<'de> OrdinaryCellParser<'de> { #[inline] pub const fn new( - r#type: CellType, level: u8, data: &'de BitSlice, references: &'de [Arc], ) -> Self { Self { - r#type, + _type: PhantomData, level, data, references, @@ -48,7 +47,7 @@ impl<'de> CellParser<'de> { /// Parse the value using its [`CellDeserialize`] implementation #[inline] - pub fn parse(&mut self) -> Result> + pub fn parse(&mut self) -> Result> where T: CellDeserialize<'de>, { @@ -58,7 +57,7 @@ impl<'de> CellParser<'de> { /// Return iterator that parses values using [`CellDeserialize`] /// implementation. #[inline] - pub fn parse_iter(&mut self) -> impl Iterator>> + '_ + pub fn parse_iter(&mut self) -> impl Iterator>> + '_ where T: CellDeserialize<'de>, { @@ -70,7 +69,7 @@ impl<'de> CellParser<'de> { /// Parse the value with args using its [`CellDeserializeWithArgs`] /// implementation. #[inline] - pub fn parse_with(&mut self, args: T::Args) -> Result> + pub fn parse_with(&mut self, args: T::Args) -> Result> where T: CellDeserializeWithArgs<'de>, { @@ -83,7 +82,7 @@ impl<'de> CellParser<'de> { pub fn parse_iter_with<'a: 'de, T>( &mut self, args: T::Args, - ) -> impl Iterator>> + '_ + ) -> impl Iterator>> + '_ where T: CellDeserializeWithArgs<'de>, T::Args: Clone + 'a, @@ -96,7 +95,7 @@ impl<'de> CellParser<'de> { /// Parse the value using an adapter. /// See [`as`](crate::as) module-level documentation for more. #[inline] - pub fn parse_as(&mut self) -> Result> + pub fn parse_as(&mut self) -> Result> where As: CellDeserializeAs<'de, T> + ?Sized, { @@ -108,7 +107,7 @@ impl<'de> CellParser<'de> { #[inline] pub fn parse_iter_as( &mut self, - ) -> impl Iterator>> + '_ + ) -> impl Iterator>> + '_ where As: CellDeserializeAs<'de, T> + ?Sized, { @@ -120,7 +119,7 @@ impl<'de> CellParser<'de> { /// Parse value with args using an adapter. /// See [`as`](crate::as) module-level documentation for more. #[inline] - pub fn parse_as_with(&mut self, args: As::Args) -> Result> + pub fn parse_as_with(&mut self, args: As::Args) -> Result> where As: CellDeserializeAsWithArgs<'de, T> + ?Sized, { @@ -133,7 +132,7 @@ impl<'de> CellParser<'de> { pub fn parse_iter_as_with<'a: 'de, T, As>( &mut self, args: As::Args, - ) -> impl Iterator>> + '_ + ) -> impl Iterator>> + '_ where As: CellDeserializeAsWithArgs<'de, T> + ?Sized, As::Args: Clone + 'a, @@ -144,7 +143,7 @@ impl<'de> CellParser<'de> { } #[inline] - fn pop_reference(&mut self) -> Result<&'de Arc, CellParserError<'de>> { + fn pop_reference(&mut self) -> Result<&'de Arc, OrdinaryCellParserError<'de>> { let (first, rest) = self .references .split_first() @@ -154,7 +153,7 @@ impl<'de> CellParser<'de> { } #[inline] - pub(crate) fn parse_reference_as(&mut self) -> Result> + pub(crate) fn parse_reference_as(&mut self) -> Result> where As: CellDeserializeAs<'de, T> + ?Sized, { @@ -165,7 +164,7 @@ impl<'de> CellParser<'de> { pub(crate) fn parse_reference_as_with( &mut self, args: As::Args, - ) -> Result> + ) -> Result> where As: CellDeserializeAsWithArgs<'de, T> + ?Sized, { @@ -200,7 +199,7 @@ impl<'de> CellParser<'de> { /// Returns an error if this parser has more data or references. #[inline] - pub fn ensure_empty(&self) -> Result<(), CellParserError<'de>> { + pub fn ensure_empty(&self) -> Result<(), OrdinaryCellParserError<'de>> { if !self.is_empty() { return Err(Error::custom(format!( "more data left: {} bits, {} references", @@ -210,21 +209,9 @@ impl<'de> CellParser<'de> { } Ok(()) } - - #[inline] - pub fn ensure_type(&self, ty: CellType) -> Result<(), CellParserError<'de>> { - if self.r#type != ty { - return Err(Error::custom(format!( - "expected cell type {}, found {}", - self.r#type, ty - ))); - } - - Ok(()) - } } -impl<'de> BitReader for CellParser<'de> { +impl<'de, C> BitReader for CellParser<'de, C> { type Error = <&'de BitSlice as BitReader>::Error; #[inline] @@ -248,11 +235,11 @@ impl<'de> BitReader for CellParser<'de> { } } -impl<'de> CellDeserialize<'de> for CellParser<'de> { +impl<'de> CellDeserialize<'de> for OrdinaryCellParser<'de> { #[inline] - fn parse(parser: &mut CellParser<'de>) -> Result> { + fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { Ok(Self { - r#type: parser.r#type, + _type: parser._type, level: parser.level, data: mem::take(&mut parser.data), references: mem::take(&mut parser.references), diff --git a/crates/tlb/src/lib.rs b/crates/tlb/src/lib.rs index 4d848b6..1878f6c 100644 --- a/crates/tlb/src/lib.rs +++ b/crates/tlb/src/lib.rs @@ -77,7 +77,7 @@ //! # r#as::{Ref, ParseFully}, //! # bits::{r#as::{NBits, VarInt}, de::BitReaderExt, ser::BitWriterExt}, //! # Cell, -//! # de::{CellDeserialize, CellParser, CellParserError}, +//! # de::{CellDeserialize, OrdinaryCellParser, OrdinaryCellParserError}, //! # Error, //! # ser::{CellSerialize, CellBuilder, CellBuilderError, CellSerializeExt}, //! # StringError, @@ -103,7 +103,7 @@ //! # } //! # } //! impl<'de> CellDeserialize<'de> for Hello { -//! fn parse(parser: &mut CellParser<'de>) -> Result> { +//! fn parse(parser: &mut OrdinaryCellParser<'de>) -> Result> { //! // tag$10 //! let tag: u8 = parser.unpack_as::<_, NBits<2>>()?; //! if tag != 0b10 {