From 256206663fd45895e52f5221182b486c0ac1a379 Mon Sep 17 00:00:00 2001 From: Wyatt Herkamp Date: Fri, 13 Oct 2023 08:21:32 -0400 Subject: [PATCH] Fixed Unresolved path for `core::any` --- CHANGELOG.md | 2 ++ Cargo.toml | 9 ++++++++- digestible/Cargo.toml | 10 +++++----- digestible/src/_private/mod.rs | 6 ++++++ digestible/src/lib.rs | 2 ++ macros/Cargo.toml | 8 ++++---- macros/src/container_attrs.rs | 2 +- macros/src/expand_enum.rs | 12 +++++++----- macros/src/expand_struct.rs | 10 ++++++---- macros/src/fields.rs | 2 +- macros/src/lib.rs | 2 +- macros/src/{consts.rs => paths.rs} | 8 ++++++++ macros/src/shared.rs | 10 ++++++---- 13 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 digestible/src/_private/mod.rs rename macros/src/{consts.rs => paths.rs} (75%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 397a99d..4ab8ed3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 0.2.2 (2023-10-13) +- Fixed Unresolved path for `core::any` ## 0.1.0 (2023-08-26) Initial release. The MVP of Digestible. diff --git a/Cargo.toml b/Cargo.toml index aad200c..3b893eb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,4 +3,11 @@ members = [ "macros", "digestible", ] -resolver = "2" \ No newline at end of file +resolver = "2" + +[workspace.package] +version = "0.2.2" +license = "MIT OR Apache-2.0" +authors = ["Wyatt Jacob Herkamp "] +repository = "https://github.com/wyatt-herkamp/digestible" +edition="2021" \ No newline at end of file diff --git a/digestible/Cargo.toml b/digestible/Cargo.toml index 6bab75f..9e8112d 100644 --- a/digestible/Cargo.toml +++ b/digestible/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "digestible" -version = "0.2.1" -edition = "2021" -authors = ["Wyatt Herkamp "] +version.workspace=true +edition.workspace=true +authors.workspace=true description = "A more dynamic Hash and Hasher trait for Rust" -license = "MIT OR Apache-2.0" +license.workspace=true categories = ["cryptography","no-std"] keywords = ["digest", "crypto", "hash"] documentation = "https://docs.rs/digestible" @@ -16,7 +16,7 @@ rust-version="1.70" [dependencies] digest_0_10 = {package = "digest", version = "0.10", optional = true } byteorder = "1" -digestible-macros= {path="../macros",optional = true, version = "0.2.1" } +digestible-macros= {path="../macros",optional = true, version = "0.2.2" } base64 = { version = "0.21", optional = true } bytes = { version = "1" , optional = true} [dev-dependencies] diff --git a/digestible/src/_private/mod.rs b/digestible/src/_private/mod.rs new file mode 100644 index 0000000..bc8b34a --- /dev/null +++ b/digestible/src/_private/mod.rs @@ -0,0 +1,6 @@ +/*! +Exports from core that are used in the macro +*/ + +pub use core::any::type_name; +pub use core::hash::{Hash, Hasher}; \ No newline at end of file diff --git a/digestible/src/lib.rs b/digestible/src/lib.rs index e878a6f..74a9529 100644 --- a/digestible/src/lib.rs +++ b/digestible/src/lib.rs @@ -70,6 +70,8 @@ pub mod digest_with; /// Provides inter-compatibility with [Hasher](core::hash::Hasher)/[Hash](core::hash::Hash) and [Digester](crate::Digester)/[Digestible](crate::Digestible) pub mod hash_digester; +#[doc(hidden)] +pub mod _private; #[doc(inline)] pub use digester_writer::DigestWriter; diff --git a/macros/Cargo.toml b/macros/Cargo.toml index 6a367a1..38a764e 100644 --- a/macros/Cargo.toml +++ b/macros/Cargo.toml @@ -1,10 +1,10 @@ [package] name = "digestible-macros" -version = "0.2.1" -edition = "2021" -authors = ["Wyatt Herkamp "] +version.workspace=true +edition.workspace=true +authors.workspace=true description = "Macros for generating digest implementations" -license = "MIT OR Apache-2.0" +license.workspace=true # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lib] diff --git a/macros/src/container_attrs.rs b/macros/src/container_attrs.rs index 7f1ee55..8db0606 100644 --- a/macros/src/container_attrs.rs +++ b/macros/src/container_attrs.rs @@ -88,5 +88,5 @@ macro_rules! get_container_attrs { .unwrap_or_default() }; } -use crate::consts::byte_order_impl_path; +use crate::paths::byte_order_impl_path; pub(crate) use get_container_attrs; diff --git a/macros/src/expand_enum.rs b/macros/src/expand_enum.rs index 6b7b1d8..1fe3ef1 100644 --- a/macros/src/expand_enum.rs +++ b/macros/src/expand_enum.rs @@ -1,10 +1,10 @@ -use crate::consts::{digest_writer, digestible_path}; +use crate::paths::{digest_writer, digestible_path, private_path}; use crate::container_attrs::{get_container_attrs, ContainerAttrs, TypeHeader}; use crate::fields::Field; use crate::shared; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote, ToTokens}; -use syn::DeriveInput; +use syn::{DeriveInput, Path}; use syn::Result; pub enum EnumType { @@ -90,7 +90,7 @@ impl ToTokens for Variant<'_> { let ident = &self.ident; let writer = self.writer; let endian = self.endian; - let byte_order_path = crate::consts::byte_order_path(); + let byte_order_path = crate::paths::byte_order_path(); let result = quote! { fn #fn_name<#endian: #byte_order_path, W: #digest_writer>( #writer: &mut W, @@ -116,8 +116,10 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result { let header_write = match container_attrs.type_header { TypeHeader::None => quote! {}, TypeHeader::HashName => { + let type_name : Path = private_path!(type_name); + quote! { - #digest_writer::write(writer, core::any::type_name::().as_bytes()); + #digest_writer::write(writer, #type_name::().as_bytes()); #digest_writer::write(writer, b"::"); } } @@ -132,7 +134,7 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result { } let catch_block: Vec<_> = variants.iter().map(|v| v.catch_block(name)).collect(); let digestible = digestible_path(); - let byte_order_path = crate::consts::byte_order_path(); + let byte_order_path = crate::paths::byte_order_path(); let impl_hash = if let Some(impl_hash) = container_attrs.impl_hash { shared::impl_hash(name, impl_hash) } else { diff --git a/macros/src/expand_struct.rs b/macros/src/expand_struct.rs index dcc3f2e..b8716d6 100644 --- a/macros/src/expand_struct.rs +++ b/macros/src/expand_struct.rs @@ -1,10 +1,10 @@ -use crate::consts::{digest_writer, digestible_path}; +use crate::paths::{digest_writer, digestible_path, private_path}; use crate::container_attrs::{get_container_attrs, ContainerAttrs, TypeHeader}; use crate::fields::Field; use crate::shared; use proc_macro2::TokenStream; use quote::{format_ident, quote}; -use syn::DeriveInput; +use syn::{DeriveInput, Path}; use syn::{Fields, Result}; pub(crate) fn expand(derive_input: DeriveInput) -> Result { @@ -40,18 +40,20 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result { }; let digest_writer = digest_writer(); + let header_write = match container_attrs.type_header { TypeHeader::None => quote! {}, TypeHeader::HashName => { + let type_name : Path = private_path!(type_name); quote! { - #digest_writer::write(writer, core::any::type_name::().as_bytes()); + #digest_writer::write(writer, #type_name::().as_bytes()); } } TypeHeader::TypeId { .. } => { todo!("type_id") } }; - let byte_order_path = crate::consts::byte_order_path(); + let byte_order_path = crate::paths::byte_order_path(); let impl_hash = if let Some(impl_hash) = container_attrs.impl_hash { shared::impl_hash(name, impl_hash) } else { diff --git a/macros/src/fields.rs b/macros/src/fields.rs index 2b41d60..b684f70 100644 --- a/macros/src/fields.rs +++ b/macros/src/fields.rs @@ -1,4 +1,4 @@ -use crate::consts::{digest_with_path, digestible_path}; +use crate::paths::{digest_with_path, digestible_path}; use proc_macro2::{Ident, TokenStream}; use quote::{format_ident, quote, ToTokens}; use syn::parse::{Parse, ParseStream}; diff --git a/macros/src/lib.rs b/macros/src/lib.rs index a2b2352..5832e70 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -1,4 +1,4 @@ -mod consts; +mod paths; mod container_attrs; mod expand_enum; mod expand_struct; diff --git a/macros/src/consts.rs b/macros/src/paths.rs similarity index 75% rename from macros/src/consts.rs rename to macros/src/paths.rs index b792aa1..ae7a2a3 100644 --- a/macros/src/consts.rs +++ b/macros/src/paths.rs @@ -20,3 +20,11 @@ pub fn byte_order_path() -> Path { pub fn byte_order_impl_path(ident: Ident) -> Path { parse_quote!(_digestible::byteorder::#ident) } + +macro_rules! private_path { + // `()` indicates that the macro takes no argument. + ($key:ident) => { + syn::parse_quote!(_digestible::_private::$key) + }; +} +pub(crate) use private_path; \ No newline at end of file diff --git a/macros/src/shared.rs b/macros/src/shared.rs index 6192542..589c01a 100644 --- a/macros/src/shared.rs +++ b/macros/src/shared.rs @@ -1,15 +1,17 @@ -use crate::consts::digester_using_hasher; +use crate::paths::{digester_using_hasher, private_path}; use proc_macro2::{Ident, TokenStream}; use quote::quote; use syn::Path; pub fn impl_hash(container: &Ident, endian_path: Path) -> TokenStream { let digester_using_hasher = digester_using_hasher(); - let digestible_path = crate::consts::digestible_path(); + let digestible_path = crate::paths::digestible_path(); + let hash: Path = private_path!(Hash); + let hasher: Path = private_path!(Hasher); quote! { #[automatically_derived] - impl core::hash::Hash for #container { - fn hash(&self, state: &mut H) { + impl #hash for #container { + fn hash(&self, state: &mut H) { let mut digester = #digester_using_hasher(state); ::digest::<#endian_path, _>(self,&mut digester); }