include-zstd 0.1.0

Compress data at compile time and include it as runtime-decompressible static bytes or strings.
Documentation
  • Coverage
  • 0%
    0 out of 1 items documented0 out of 0 items with examples
  • Size
  • Source code size: 13.21 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 256.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 1m 25s Average build duration of successful builds.
  • all releases: 1m 25s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • fawdlstty/include-zstd
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • fawdlstty

include-zstd

version status

English | 简体中文

include-zstd is a Rust macro library that compresses text or binary data at compile time and decompresses it on demand at runtime, returning either &'static str or &'static [u8].

Usage

1. Add dependency

Run:

cargo add include-zstd

2. Common macros

  • include_zstd::str!("..."): inline string, returns &'static str
  • include_zstd::bytes!(b"..."): inline byte string, returns &'static [u8]
  • include_zstd::file_str!("path"): reads a file and returns &'static str as UTF-8
  • include_zstd::file_bytes!("path"): reads a file and returns &'static [u8]

Path resolution for include_zstd::file_str! / include_zstd::file_bytes! is the same as include_str! / include_bytes!: relative paths are resolved from the directory of the source file where the macro is invoked.

4. Example

fn main() {
    let msg: &'static str = include_zstd::str!("hello include-zstd");
    let raw: &'static [u8] = include_zstd::bytes!(b"\x00\x01\x02\x03");

    let text: &'static str = include_zstd::file_str!("data/sample.txt");
    let bytes: &'static [u8] = include_zstd::file_bytes!("data/sample.bin");

    println!("msg={msg}, text_len={}, bytes_len={}, raw_len={}", text.len(), bytes.len(), raw.len());
}