Compare commits
3 Commits
c6537f2117
...
6a37f26eaa
| Author | SHA1 | Date | |
|---|---|---|---|
|
6a37f26eaa
|
|||
|
2167ee28fd
|
|||
|
34b1140573
|
@@ -1,7 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "const-macros"
|
name = "const-macros"
|
||||||
description = "Crate with some useful macros for const-time stuff"
|
description = "Crate with some useful macros for const-time stuff"
|
||||||
version = "0.1.0"
|
version = "0.1.1"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
repository = "https://git.javalsai.tuxcord.net/rust/const-macros"
|
repository = "https://git.javalsai.tuxcord.net/rust/const-macros"
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
#![feature(proc_macro_value)]
|
#![feature(proc_macro_value)]
|
||||||
use std::{fs::File, io::Read};
|
use std::{fs::File, io::Read, path::Path};
|
||||||
|
|
||||||
use proc_macro::{Delimiter, Group, Literal, Punct, TokenStream, TokenTree};
|
use proc_macro::{Delimiter, Group, Literal, Punct, TokenStream, TokenTree};
|
||||||
use sha2::Digest;
|
use sha2::Digest;
|
||||||
|
|
||||||
fn read_path_literal(input: TokenStream) -> String {
|
fn read_path_literal(input: TokenStream) -> String {
|
||||||
println!("{input:?}");
|
|
||||||
let mut input_iter = input.into_iter();
|
let mut input_iter = input.into_iter();
|
||||||
let path_token = input_iter.next().expect("expected a path");
|
let path_token = input_iter.next().expect("expected a path");
|
||||||
assert!(input_iter.next().is_none(), "only expected one argument");
|
assert!(input_iter.next().is_none(), "only expected one argument");
|
||||||
@@ -115,7 +114,10 @@ fn get_sha256sum(buf: &[u8]) -> [u8; 32] {
|
|||||||
pub fn include_asset(input: TokenStream) -> TokenStream {
|
pub fn include_asset(input: TokenStream) -> TokenStream {
|
||||||
let path = read_path_literal(input);
|
let path = read_path_literal(input);
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
File::open(path)
|
|
||||||
|
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR to be set");
|
||||||
|
|
||||||
|
File::open(Path::new(&manifest_dir).join(&path))
|
||||||
.expect("couldn't open file")
|
.expect("couldn't open file")
|
||||||
.read_to_end(&mut buf)
|
.read_to_end(&mut buf)
|
||||||
.expect("error reading file");
|
.expect("error reading file");
|
||||||
|
|||||||
@@ -27,6 +27,10 @@ pub mod file {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Similar to [`include_bytes!`], but it returns a lot more information about the file, like
|
||||||
|
/// its mime type, or its sha256sum (could be changed), all at compile time.
|
||||||
|
///
|
||||||
|
/// The path is relative to the package's root.
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! include_asset {
|
macro_rules! include_asset {
|
||||||
($path:literal) => {
|
($path:literal) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user