Skip to content

Commit

Permalink
Fixed Unresolved path for core::any
Browse files Browse the repository at this point in the history
  • Loading branch information
wyatt-herkamp committed Oct 13, 2023
1 parent 21a55bf commit 2562066
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 26 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 8 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,11 @@ members = [
"macros",
"digestible",
]
resolver = "2"
resolver = "2"

[workspace.package]
version = "0.2.2"
license = "MIT OR Apache-2.0"
authors = ["Wyatt Jacob Herkamp <[email protected]>"]
repository = "https://github.com/wyatt-herkamp/digestible"
edition="2021"
10 changes: 5 additions & 5 deletions digestible/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "digestible"
version = "0.2.1"
edition = "2021"
authors = ["Wyatt Herkamp <[email protected]>"]
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"
Expand All @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions digestible/src/_private/mod.rs
Original file line number Diff line number Diff line change
@@ -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};
2 changes: 2 additions & 0 deletions digestible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[package]
name = "digestible-macros"
version = "0.2.1"
edition = "2021"
authors = ["Wyatt Herkamp <[email protected]>"]
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]
Expand Down
2 changes: 1 addition & 1 deletion macros/src/container_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
12 changes: 7 additions & 5 deletions macros/src/expand_enum.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand All @@ -116,8 +116,10 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result<TokenStream> {
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::<Self>().as_bytes());
#digest_writer::write(writer, #type_name::<Self>().as_bytes());
#digest_writer::write(writer, b"::");
}
}
Expand All @@ -132,7 +134,7 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result<TokenStream> {
}
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 {
Expand Down
10 changes: 6 additions & 4 deletions macros/src/expand_struct.rs
Original file line number Diff line number Diff line change
@@ -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<TokenStream> {
Expand Down Expand Up @@ -40,18 +40,20 @@ pub(crate) fn expand(derive_input: DeriveInput) -> Result<TokenStream> {
};

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::<Self>().as_bytes());
#digest_writer::write(writer, #type_name::<Self>().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 {
Expand Down
2 changes: 1 addition & 1 deletion macros/src/fields.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion macros/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mod consts;
mod paths;
mod container_attrs;
mod expand_enum;
mod expand_struct;
Expand Down
8 changes: 8 additions & 0 deletions macros/src/consts.rs → macros/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
10 changes: 6 additions & 4 deletions macros/src/shared.rs
Original file line number Diff line number Diff line change
@@ -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<H: core::hash::Hasher>(&self, state: &mut H) {
impl #hash for #container {
fn hash<H: #hasher>(&self, state: &mut H) {
let mut digester = #digester_using_hasher(state);
<Self as #digestible_path>::digest::<#endian_path, _>(self,&mut digester);
}
Expand Down

0 comments on commit 2562066

Please sign in to comment.