From 4add7f22f9186ad5787d19b9aef92df5486360cf Mon Sep 17 00:00:00 2001 From: javalsai Date: Tue, 24 Mar 2026 22:53:53 +0100 Subject: [PATCH] feat: add str shasum prop --- const-macros-proc/src/lib.rs | 8 ++++++++ src/lib.rs | 10 ++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/const-macros-proc/src/lib.rs b/const-macros-proc/src/lib.rs index 76affa7..99c08e7 100644 --- a/const-macros-proc/src/lib.rs +++ b/const-macros-proc/src/lib.rs @@ -87,6 +87,14 @@ fn extend_asset_tuple(ts: &mut TokenStream, buf: &[u8], mime: &str, sha256sum: [ extend_array(&mut ts, &sha256sum); ts }, + { + let mut ts = TokenStream::new(); + let sha_str = sha256sum + .iter() + .fold(String::new(), |acc, b| acc + &format!("{b:02x}")); + ts.extend(std::iter::once(Literal::string(&sha_str))); + ts + }, ] .into_iter(), ); diff --git a/src/lib.rs b/src/lib.rs index b3df8a0..08e5360 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,12 +2,13 @@ // learn about [`proc_macro`] so I'm not gonna use [`quote`] or [`syn`] pub mod file { - pub type IncludeAssetMacroTy = (&'static [u8], &'static str, [u8; 32]); + pub type IncludeAssetMacroTy = (&'static [u8], &'static str, [u8; 32], &'static str); pub struct FileAsset { pub bytes: &'static [u8], pub mime: &'static str, pub shasum: [u8; 32], + pub shasum_str: &'static str, } impl FileAsset { @@ -17,12 +18,13 @@ pub mod file { bytes: tuple.0, mime: tuple.1, shasum: tuple.2, + shasum_str: tuple.3, } } } impl From for FileAsset { - fn from(value: (&'static [u8], &'static str, [u8; 32])) -> Self { + fn from(value: IncludeAssetMacroTy) -> Self { Self::from_tuple(value) } } @@ -50,6 +52,10 @@ pub mod file { assert_eq!(ASSET1.bytes, b"This is just a bunch of bytes that will hash to a known sequence and I can test for validity\n"); assert_eq!(ASSET1.mime, "text/plain; charset=us-ascii"); + assert_eq!( + ASSET1.shasum_str, + "4f72ae5a7e2d70fec413af0e298f1b7a7c1d8d9caf4fd624460d2fe2d81b8328" + ); assert_eq!( ASSET1.shasum, [