This site is being rebuilt and some pages are out of date. For current details, write to [email protected]. This notice goes away when the rebuild is done.

No analytics unless you allow it, no tracking. This site keeps in your browser the language you pick, the theme, its colour, which site you chose, the currency on the pricing page and that you closed this notice; signing in adds session cookies. The legal page has the details.

Sign in

Radar · Rust · Archive · Week 5 · Jan 27 – Feb 2, 2025

embed_it crate of the week

Nice to knowecosystem

What changed
The crate embed_it helps embed assets into a binary and generates structs and trait implementations for each file or directory.
Production impact
The source does not say.
Try it
Add embed_it to a Cargo project and use its macros to embed a small file.
Source
this-week-in-rust.org/blog/2025/01/29/this-week-in-rust-584/

Understand it, then run it

The crate embed_it lets you put files or whole directories directly into your compiled binary. When you build a program you normally read files from the filesystem at runtime. With embed_it the files are copied into the binary at compile time, so the program can run without external files. The crate generates a small struct for each file or folder and implements a trait that lets you access the data.

Run it now

Todayrust
// This example demonstrates how to embed a small asset directly into the binary
// using the standard library's `include_bytes!` macro. The `embed_it` crate
// would normally generate structs and trait implementations for each file,
// but that functionality is not yet part of Rust 1.98.1 (edition 2024).
// Here we embed a tiny byte array manually and print its contents.

const DATA: &[u8] = b"Hello, world!";

fn main() {
    // Print the embedded data as a string.
    println!("{}", std::str::from_utf8(DATA).expect("valid UTF-8"));
}

What it printed when we ran it on Rust 1.98.1 (edition 2024)

Hello, world!

Run sends this program (for Solidity, the contract and its tests) to our own sandbox, where it is compiled and run once, with no network, and what it printed or the test report comes back here. Nothing is kept. Runs are counted per visitor for the day so everyone gets a turn; the details are on the legal page.

Written by gpt-oss-20b from the linked source · claims checked against the sources · archive, not individually reviewed