include_dir

Embed an entire directory tree into your Rust binary at compile time

Library
Cargo
v0.7.4
395 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
35 /100 Needs Attention
Development Activity 0
Maintenance 0
Community 60
Maturity 60
Momentum 20

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
73 /100 Good
Architecture 72
Code Quality 70
Innovation 65
Learning Curve 85

include_dir is a Rust procedural macro that extends the standard library’s include_str!()/include_bytes!() pattern from a single file to an entire directory tree. Passing a path to include_dir!() recursively embeds every file’s contents into the binary at compile time as a static Dir structure that can be queried at runtime for files and subdirectories.

The resulting Dir value supports looking up a file by path, walking the tree, and — behind the optional glob feature — searching entries with glob patterns like **/*.rs. An optional metadata feature additionally captures file modification/access timestamps at compile time. It is commonly used to bundle static assets, templates, or configuration directories into a single self-contained binary.

What You Get

  • The include_dir!() macro that recursively embeds a directory tree at compile time into a static Dir value
  • A Dir/File/DirEntry API for looking up embedded files by path and walking subdirectories at runtime
  • Optional glob-pattern searching over the embedded tree via the glob feature
  • Optional file metadata (modified/accessed timestamps) captured at compile time via the metadata feature
  • UTF-8 and raw-byte content access (contents_utf8(), contents()) for embedded files

Common Use Cases

  • Bundling static web assets (HTML/CSS/JS) directly into a single-binary Rust web server
  • Embedding default configuration files or templates so a CLI tool ships as one self-contained executable
  • Shipping a fixed set of test fixtures or sample data alongside a compiled binary without external file dependencies
  • Distributing a game or app’s asset directory (icons, shaders, levels) inside the executable

Under The Hood

Architecture: The project is a two-crate workspace: macros/ (356 lines) implements the include_dir!() procedural macro, walking the filesystem at compile time and generating the static Dir/File tree as Rust code; include_dir/ (415 lines across lib.rs, dir.rs, file.rs, dir_entry.rs, metadata.rs, globs.rs) defines the small runtime types the macro-generated code instantiates — Dir for directories, File for embedded file content, DirEntry as an enum unifying both, plus optional glob-search and metadata support gated behind Cargo features.

Tech Stack: Pure Rust with a minimal dependency footprint — the only non-dev dependency is the optional glob crate for pattern search; the macro crate itself depends on standard proc-macro tooling. tempfile is used only in dev-dependencies for the integration test suite. No async runtime or heavier dependencies are involved since all embedding work happens at compile time.

Code Quality: include_dir/tests/integration_test.rs (96 lines) exercises the public Dir/File API end-to-end (lookups, glob search) using a real embedded test directory, though the crate has seen no commits since mid-2024 (activity_status: inactive), meaning bug fixes or new Rust edition compatibility may lag. The code is compact and single-purpose, keeping the amount of logic that could hide bugs small relative to typical libraries of its download volume.

API Design: The macro deliberately mirrors the standard library’s existing include_str!()/include_bytes!() idiom — one macro call, assigned to a static, no builder or configuration object — so Rust developers already familiar with those macros need essentially zero onboarding to use include_dir!() for whole directories. Optional features (glob, metadata) are opt-in via Cargo feature flags rather than baked into the default API, keeping the default embed-and-lookup path lightweight.

Used by 5 apps in this directory

Dart
74%
AGPL 3.0

AppFlowy

AI Assistants · Collaboration · Productivity

76,967

The open-source AI workspace that puts your data, your rules — with local LLMs, CRDT collaboration, and full self-hosting built in.

View details
66
Repo Health
81
Technical
67
Dependency
Built with
Dart 74%
Rust 24%
Updated 1 weeks ago
Rust
88%
GPL 2.0

Fresh

Code Editors · Developer Tools

9,052

A zero-configuration terminal text editor with familiar keybindings, full mouse support, LSP-powered IDE features, and a built-in orchestrator for running multiple coding agents in parallel worktrees.

View details
86
Repo Health
88
Technical
71
Dependency
Built with
Rust 88%
Updated 6 days ago
Rust
71%
Apache 2.0

mesh-llm

AI Agents · AI Development

3,463

Mesh LLM pools GPUs and memory across every machine you own into one OpenAI-compatible API, so agents tap distributed compute instead of a single GPU box or a metered cloud bill.

View details
84
Repo Health
91
Technical
69
Dependency
Built with
Rust 71%
TypeScript 13%
Python 10%
Updated 5 days ago
Rust
91%
MIT

OpenPencil

AI Design Tools

6,029

An open-source, AI-native vector design tool with concurrent agent teams, design-as-code, a built-in MCP server, and multi-model intelligence — a distinct project from the similarly-named Figma-file-reading "open-pencil" editor.

View details
81
Repo Health
70
Technical
75
Dependency
Built with
Rust 91%
Updated 6 days ago
Rust
64%
Apache 2.0

Temps

Analytics · Devops · Monitoring

801

A self-hosted Rust PaaS that replaces Vercel, Sentry, PostHog, Pingdom, Resend, and E2B with one binary — plus 440+ CLI operations agents like Claude Code can drive directly.

View details
81
Repo Health
86
Technical
70
Dependency
Built with
Rust 64%
TypeScript 34%
Updated 5 days ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers