Skip to main content

Crate rust_embed_url

Crate rust_embed_url 

Source
Expand description

§rust-embed-url

A procedural macro for embedding URL content at compile time with SHA-256 hash verification.

§Features

  • Fetches URL content during compilation
  • Verifies content integrity using SHA-256 checksums
  • Returns embedded bytes as Box<[u8]>
  • Fails fast with clear error messages on mismatch or network failures

§Usage

ⓘ
use rust_embed_url::embed_url;

fn main() {
    let data = embed_url!(
        "https://example.com",
        "ZmY2N2E5ZDc2NGQ2YTIzNjdhMTg3NzM0ZTY5N2Y2YTUzMjE3ZGI5YTIxYzEwMWQ0MTBhMTEzY2E4NzFhMjk5ZAo="
    );
    let content = String::from_utf8(data.into()).unwrap();
    println!("{}", content);
}

§Computing the Hash

To compute the SHA-256 hash (base64 encoded) for your URL:

curl -s "https://example.com" | sha256sum | cut -d' ' -f1 | base64

Macros§

embed_url
Procedural macro that embeds URL content at compile time with hash verification.