feat: re-export used deps from reth-codecs (#13167)

This commit is contained in:
Matthias Seitz
2024-12-06 09:45:30 +01:00
committed by GitHub
parent 6fc4e8acd2
commit da98285469
6 changed files with 22 additions and 9 deletions

View File

@ -26,7 +26,7 @@ op-alloy-consensus = { workspace = true, optional = true }
# misc
bytes.workspace = true
modular-bitfield = { workspace = true, optional = true }
modular-bitfield.workspace = true
visibility = { version = "0.1.1", optional = true}
serde.workspace = true
arbitrary = { workspace = true, features = ["derive"], optional = true }
@ -65,7 +65,6 @@ alloy = [
"dep:alloy-consensus",
"dep:alloy-eips",
"dep:alloy-genesis",
"dep:modular-bitfield",
"dep:alloy-trie",
]
op = ["alloy", "dep:op-alloy-consensus"]

View File

@ -1,9 +1,11 @@
use super::*;
use syn::Attribute;
/// Generates the flag fieldset struct that is going to be used to store the length of fields and
/// their potential presence.
pub(crate) fn generate_flag_struct(
ident: &Ident,
attrs: &[Attribute],
has_lifetime: bool,
fields: &FieldList,
is_zstd: bool,
@ -13,6 +15,8 @@ pub(crate) fn generate_flag_struct(
let flags_ident = format_ident!("{ident}Flags");
let mod_flags_ident = format_ident!("{ident}_flags");
let reth_codecs = parse_reth_codecs_path(attrs).unwrap();
let mut field_flags = vec![];
let total_bits = if is_enum {
@ -88,8 +92,9 @@ pub(crate) fn generate_flag_struct(
pub use #mod_flags_ident::#flags_ident;
#[allow(non_snake_case)]
mod #mod_flags_ident {
use bytes::Buf;
use modular_bitfield::prelude::*;
use #reth_codecs::__private::Buf;
use #reth_codecs::__private::modular_bitfield;
use #reth_codecs::__private::modular_bitfield::prelude::*;
#[doc = #docs]
#[bitfield]

View File

@ -239,7 +239,7 @@ fn generate_to_compact(fields: &FieldList, ident: &Ident, is_zstd: bool) -> Vec<
}
/// Function to extract the crate path from `reth_codecs(crate = "...")` attribute.
fn parse_reth_codecs_path(attrs: &[Attribute]) -> syn::Result<syn::Path> {
pub(crate) fn parse_reth_codecs_path(attrs: &[Attribute]) -> syn::Result<syn::Path> {
// let default_crate_path: syn::Path = syn::parse_str("reth-codecs").unwrap();
let mut reth_codecs_path: syn::Path = syn::parse_quote!(reth_codecs);
for attr in attrs {

View File

@ -48,7 +48,7 @@ pub fn derive(input: TokenStream, is_zstd: bool) -> TokenStream {
let has_lifetime = has_lifetime(&generics);
let fields = get_fields(&data);
output.extend(generate_flag_struct(&ident, has_lifetime, &fields, is_zstd));
output.extend(generate_flag_struct(&ident, &attrs, has_lifetime, &fields, is_zstd));
output.extend(generate_from_to(&ident, &attrs, has_lifetime, &fields, is_zstd));
output.into()
}
@ -235,7 +235,7 @@ mod tests {
let mut output = quote! {};
let DeriveInput { ident, data, attrs, .. } = parse2(f_struct).unwrap();
let fields = get_fields(&data);
output.extend(generate_flag_struct(&ident, false, &fields, false));
output.extend(generate_flag_struct(&ident, &attrs, false, &fields, false));
output.extend(generate_from_to(&ident, &attrs, false, &fields, false));
// Expected output in a TokenStream format. Commas matter!
@ -255,8 +255,9 @@ mod tests {
#[allow(non_snake_case)]
mod TestStruct_flags {
use bytes::Buf;
use modular_bitfield::prelude::*;
use reth_codecs::__private::Buf;
use reth_codecs::__private::modular_bitfield;
use reth_codecs::__private::modular_bitfield::prelude::*;
#[doc = "Fieldset that facilitates compacting the parent type. Used bytes: 2 | Unused bits: 1"]
#[bitfield]
#[derive(Clone, Copy, Debug, Default)]

View File

@ -39,6 +39,11 @@ pub mod txtype;
#[cfg(any(test, feature = "test-utils"))]
pub mod test_utils;
// Used by generated code and doc tests. Not public API.
#[doc(hidden)]
#[path = "private.rs"]
pub mod __private;
/// Trait that implements the `Compact` codec.
///
/// When deriving the trait for custom structs, be aware of certain limitations/recommendations:

View File

@ -0,0 +1,3 @@
pub use modular_bitfield;
pub use bytes::Buf;