Skip to content

Commit

Permalink
Use b"" instead of &[u8] for literal bytes, fixes #2
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Aug 14, 2019
1 parent 9cebc4f commit 535b763
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ categories = ["compression", "rust-patterns", "memory-management"]
keywords = ["compression", "deflate", "macro", "include", "assets"]

[dependencies]
include-flate-codegen = {version = "0.1.0", path = "codegen"}
include-flate-codegen = {version = "0.1.2", path = "codegen"}
lazy_static = "1.3"
libflate = "0.1.26"

Expand Down
10 changes: 5 additions & 5 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use std::str::from_utf8;

use libflate::deflate::Encoder;
use proc_macro::TokenStream;
use proc_macro2::{Literal, Span};
use proc_macro2::Span;
use quote::quote;
use syn::{Error, LitStr, Result};
use syn::{Error, LitByteStr, LitStr, Result};

/// `deflate_file!("file")` is equivalent to `include_bytes!("file.gz")`.
///
Expand All @@ -37,7 +37,7 @@ use syn::{Error, LitStr, Result};
/// `CARGO_MANIFEST_DIR`.
///
/// # Returns
/// This macro expands to a `&[u8]` literal that contains the deflated form of the file.
/// This macro expands to a `b"byte string"` literal that contains the deflated form of the file.
///
/// # Compile errors
/// - If the argument is not a single literal
Expand Down Expand Up @@ -95,8 +95,8 @@ fn inner(ts: TokenStream, utf8: bool) -> Result<impl Into<TokenStream>> {
}
let bytes = encoder.finish().into_result().map_err(emap)?;

let bytes = bytes.into_iter().map(|byte| Literal::u8_suffixed(byte));
let result = quote!(&[#(#bytes),*]);
let bytes = LitByteStr::new(&bytes, Span::call_site());
let result = quote!(#bytes);

Ok(result)
}
1 change: 0 additions & 1 deletion tests/ff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,4 @@ flate!(pub static DATA: [u8] from "assets/ff.dat");
#[test]
fn test() {
verify("ff.dat", &DATA);

}
File renamed without changes.

0 comments on commit 535b763

Please sign in to comment.