feat: add str shasum prop
This commit is contained in:
@@ -87,6 +87,14 @@ fn extend_asset_tuple(ts: &mut TokenStream, buf: &[u8], mime: &str, sha256sum: [
|
|||||||
extend_array(&mut ts, &sha256sum);
|
extend_array(&mut ts, &sha256sum);
|
||||||
ts
|
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(),
|
.into_iter(),
|
||||||
);
|
);
|
||||||
|
|||||||
10
src/lib.rs
10
src/lib.rs
@@ -2,12 +2,13 @@
|
|||||||
// learn about [`proc_macro`] so I'm not gonna use [`quote`] or [`syn`]
|
// learn about [`proc_macro`] so I'm not gonna use [`quote`] or [`syn`]
|
||||||
|
|
||||||
pub mod file {
|
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 struct FileAsset {
|
||||||
pub bytes: &'static [u8],
|
pub bytes: &'static [u8],
|
||||||
pub mime: &'static str,
|
pub mime: &'static str,
|
||||||
pub shasum: [u8; 32],
|
pub shasum: [u8; 32],
|
||||||
|
pub shasum_str: &'static str,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FileAsset {
|
impl FileAsset {
|
||||||
@@ -17,12 +18,13 @@ pub mod file {
|
|||||||
bytes: tuple.0,
|
bytes: tuple.0,
|
||||||
mime: tuple.1,
|
mime: tuple.1,
|
||||||
shasum: tuple.2,
|
shasum: tuple.2,
|
||||||
|
shasum_str: tuple.3,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<IncludeAssetMacroTy> for FileAsset {
|
impl From<IncludeAssetMacroTy> for FileAsset {
|
||||||
fn from(value: (&'static [u8], &'static str, [u8; 32])) -> Self {
|
fn from(value: IncludeAssetMacroTy) -> Self {
|
||||||
Self::from_tuple(value)
|
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.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.mime, "text/plain; charset=us-ascii");
|
||||||
|
assert_eq!(
|
||||||
|
ASSET1.shasum_str,
|
||||||
|
"4f72ae5a7e2d70fec413af0e298f1b7a7c1d8d9caf4fd624460d2fe2d81b8328"
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
ASSET1.shasum,
|
ASSET1.shasum,
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user