mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 14:47:55 +00:00
Add bitvec-like generic support to the scale-bits type for use in codegen (#718)
* Add bitvec-like generic support to the scale-bits type for use in codegen * Use nightly 1.66 formatting * Fix reading input while decoding bit sequences * Add tests for our DecodedBits wrapper * Add convenience DecodedBits::(in)to_bits functions * Don't expose DecodedBits::bit_format * Re-export scale_bits as peer dependency * Move subxt::utils into a separate file * Hide DecodedBits internals * Don't re-export types from the `bits` module * Update subxt/src/utils/bits.rs Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> * Update subxt/src/utils/bits.rs Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com> * Address review feedback * Clarify the byte needed calculation in DecodedBits encoding * Remove remaining dbg! invocations Co-authored-by: Niklas Adolfsson <niklasadolfsson1@gmail.com>
This commit is contained in:
@@ -745,10 +745,22 @@ fn generate_bitvec() {
|
||||
registry.register_type(&meta_type::<S>());
|
||||
let portable_types: PortableRegistry = registry.into();
|
||||
|
||||
let substitutes = [
|
||||
(
|
||||
String::from("bitvec::order::Lsb0"),
|
||||
parse_quote!(::subxt_path::utils::bits::Lsb0),
|
||||
),
|
||||
(
|
||||
String::from("bitvec::order::Msb0"),
|
||||
parse_quote!(::subxt_path::utils::bits::Msb0),
|
||||
),
|
||||
]
|
||||
.into();
|
||||
|
||||
let type_gen = TypeGenerator::new(
|
||||
&portable_types,
|
||||
"root",
|
||||
Default::default(),
|
||||
substitutes,
|
||||
DerivesRegistry::new(&"::subxt_path".into()),
|
||||
"::subxt_path".into(),
|
||||
);
|
||||
@@ -762,8 +774,8 @@ fn generate_bitvec() {
|
||||
use super::root;
|
||||
#[derive(::subxt_path::ext::codec::Decode, ::subxt_path::ext::codec::Encode, Debug)]
|
||||
pub struct S {
|
||||
pub lsb: ::subxt_path::ext::bitvec::vec::BitVec<::core::primitive::u8, root::bitvec::order::Lsb0>,
|
||||
pub msb: ::subxt_path::ext::bitvec::vec::BitVec<::core::primitive::u16, root::bitvec::order::Msb0>,
|
||||
pub lsb: ::subxt_path::utils::bits::DecodedBits<::core::primitive::u8, ::subxt_path::utils::bits::Lsb0>,
|
||||
pub msb: ::subxt_path::utils::bits::DecodedBits<::core::primitive::u16, ::subxt_path::utils::bits::Msb0>,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -246,7 +246,7 @@ impl TypePathType {
|
||||
bit_store_type,
|
||||
crate_path,
|
||||
} => {
|
||||
let type_path = parse_quote! { #crate_path::ext::bitvec::vec::BitVec<#bit_store_type, #bit_order_type> };
|
||||
let type_path = parse_quote! { #crate_path::utils::bits::DecodedBits<#bit_store_type, #bit_order_type> };
|
||||
syn::Type::Path(type_path)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user