{"id":13484815,"url":"https://github.com/pyrossh/rust-embed","last_synced_at":"2025-05-14T09:06:37.202Z","repository":{"id":38391835,"uuid":"47065398","full_name":"pyrossh/rust-embed","owner":"pyrossh","description":"Rust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.","archived":true,"fork":false,"pushed_at":"2025-04-10T17:34:44.000Z","size":1352,"stargazers_count":1767,"open_issues_count":15,"forks_count":91,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-05-07T19:11:40.231Z","etag":null,"topics":["code-generator","rust","rust-lang","server","static-server"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyrossh.png","metadata":{"files":{"readme":"readme.md","changelog":"changelog.md","contributing":null,"funding":null,"license":"license","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2015-11-29T13:52:55.000Z","updated_at":"2025-04-30T11:42:24.000Z","dependencies_parsed_at":"2024-02-25T13:39:08.594Z","dependency_job_id":"4fc31338-56d8-4840-9182-c680ca68bf61","html_url":"https://github.com/pyrossh/rust-embed","commit_stats":{"total_commits":367,"total_committers":62,"mean_commits":5.919354838709677,"dds":0.6648501362397821,"last_synced_commit":"edeab18bd159cd685b0557d373d04584bbea06a9"},"previous_names":["pyros2097/rust-embed"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyrossh%2Frust-embed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyrossh%2Frust-embed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyrossh%2Frust-embed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyrossh%2Frust-embed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyrossh","download_url":"https://codeload.github.com/pyrossh/rust-embed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254110374,"owners_count":22016391,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generator","rust","rust-lang","server","static-server"],"created_at":"2024-07-31T17:01:34.668Z","updated_at":"2025-05-14T09:06:32.192Z","avatar_url":"https://github.com/pyrossh.png","language":"Rust","readme":"# ** Decomissioning of my github profile **\n\nNew rust-embed location,\n**https://git.sr.ht/~pyrossh/rust-embed**\n\n\n## Rust Embed [![Build Status](https://github.com/pyros2097/rust-embed/workflows/Test/badge.svg)](https://github.com/pyros2097/rust-embed/actions?query=workflow%3ATest) [![crates.io](https://img.shields.io/crates/v/rust-embed.svg)](https://crates.io/crates/rust-embed)\n\nRust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.\n\nYou can use this to embed your css, js and images into a single executable which can be deployed to your servers. Also it makes it easy to build a very small docker image for you to deploy.\n\n## Installation\n\n```toml\n[dependencies]\nrust-embed=\"8.7.0\"\n```\n\n## Documentation\n\nYou need to add the custom derive macro RustEmbed to your struct with an attribute `folder` which is the path to your static folder.\n\nThe path resolution works as follows:\n\n- In `debug` and when `debug-embed` feature is not enabled, the folder path is resolved relative to where the binary is run from.\n- In `release` or when `debug-embed` feature is enabled, the folder path is resolved relative to where `Cargo.toml` is.\n\n```rust\n#[derive(Embed)]\n#[folder = \"examples/public/\"]\nstruct Asset;\n```\n\nThe macro will generate the following code:\n\n```rust\nimpl Asset {\n  pub fn get(file_path: \u0026str) -\u003e Option\u003crust_embed::EmbeddedFile\u003e {\n    ...\n  }\n\n  pub fn iter() -\u003e impl Iterator\u003cItem = Cow\u003c'static, str\u003e\u003e {\n    ...\n  }\n}\nimpl RustEmbed for Asset {\n  fn get(file_path: \u0026str) -\u003e Option\u003crust_embed::EmbeddedFile\u003e {\n    ...\n  }\n  fn iter() -\u003e impl Iterator\u003cItem = Cow\u003c'static, str\u003e\u003e {\n    ...\n  }\n}\n\n// Where EmbeddedFile contains these fields,\npub struct EmbeddedFile {\n  pub data: Cow\u003c'static, [u8]\u003e,\n  pub metadata: Metadata,\n}\npub struct Metadata {\n  hash: [u8; 32],\n  last_modified: Option\u003cu64\u003e,\n  created: Option\u003cu64\u003e,\n}\n```\n\n### `get(file_path: \u0026str) -\u003e Option\u003crust_embed::EmbeddedFile\u003e`\n\nGiven a relative path from the assets folder returns the `EmbeddedFile` if found.\n\nIf the feature `debug-embed` is enabled or the binary compiled in release mode the bytes have been embeded in the binary and a `Option\u003crust_embed::EmbeddedFile\u003e` is returned.\n\nOtherwise the bytes are read from the file system on each call and a `Option\u003crust_embed::EmbeddedFile\u003e` is returned.\n\n### `iter()`\n\nIterates the files in this assets folder.\n\nIf the feature `debug-embed` is enabled or the binary compiled in release mode a static array to the list of relative paths to the files is returned.\n\nOtherwise the files are listed from the file system on each call.\n\n## Attributes\n### `prefix`\n\nYou can add `#[prefix = \"my_prefix/\"]` to the `RustEmbed` struct to add a prefix\nto all of the file paths. This prefix will be required on `get` calls, and will\nbe included in the file paths returned by `iter`.\n\n### `metadata_only`\n\nYou can add `#[metadata_only = true]` to the `RustEmbed` struct to exclude file contents from the\nbinary. Only file paths and metadata will be embedded.\n\n### `allow_missing`\n\nYou can add `#[allow_missing = true]` to the `RustEmbed` struct to allow the embedded folder to be missing.\nIn that case, RustEmbed will be empty.\n\n## Features\n\n### `debug-embed`\n\nAlways embed the files in the binary, even in debug mode.\n\n### `interpolate-folder-path`\n\nAllow environment variables to be used in the `folder` path. Example:\n\n```rust\n#[derive(Embed)]\n#[folder = \"$CARGO_MANIFEST_DIR/foo\"]\nstruct Asset;\n```\n\nThis will pull the `foo` directory relative to your `Cargo.toml` file.\n\n### `compression`\n\nCompress each file when embedding into the binary. Compression is done via [`include-flate`].\n\n### `include-exclude`\nFilter files to be embedded with multiple `#[include = \"*.txt\"]` and `#[exclude = \"*.jpg\"]` attributes. \nMatching is done on relative file paths, via [`globset`].\n`exclude` attributes have higher priority than `include` attributes.\nExample:\n\n```rust\nuse rust_embed::Embed;\n\n#[derive(Embed)]\n#[folder = \"examples/public/\"]\n#[include = \"*.html\"]\n#[include = \"images/*\"]\n#[exclude = \"*.txt\"]\nstruct Asset;\n```\n\n### `deterministic-timestamps`\nOverwrite embedded files' timestamps with `0` to preserve deterministic builds with `debug-embed` or release mode\n\n## Usage\n\n```rust\nuse rust_embed::Embed;\n\n#[derive(Embed)]\n#[folder = \"examples/public/\"]\n#[prefix = \"prefix/\"]\nstruct Asset;\n\nfn main() {\n  let index_html = Asset::get(\"prefix/index.html\").unwrap();\n  println!(\"{:?}\", std::str::from_utf8(index_html.data.as_ref()));\n\n  for file in Asset::iter() {\n      println!(\"{}\", file.as_ref());\n  }\n}\n```\n\n## Integrations\n\n1. [Poem](https://github.com/poem-web/poem) for poem framework under feature flag \"embed\"\n2. [warp_embed](https://docs.rs/warp-embed/latest/warp_embed/) for warp framework\n\n## Examples\n\nTo run the example in dev mode where it reads from the fs,\n\n`cargo run --example basic`\n\nTo run the example in release mode where it reads from binary,\n\n`cargo run --example basic --release`\n\nNote: To run the [actix-web](https://github.com/actix/actix-web) example:\n\n`cargo run --example actix --features actix`\n\nNote: To run the [rocket](https://github.com/SergioBenitez/Rocket) example:\n\n`cargo run --example rocket --features rocket`\n\nNote: To run the [warp](https://github.com/seanmonstar/warp) example:\n\n`cargo run --example warp --features warp-ex`\n\nNote: To run the [axum](https://github.com/tokio-rs/axum) example:\n\n`cargo run --example axum --features axum-ex`\n\nNote: To run the [poem](https://github.com/poem-web/poem) example:\n\n`cargo run --example poem --features poem-ex`\n\nNote: To run the [salvo](https://github.com/salvo-rs/salvo) example:\n\n`cargo run --example salvo --features salvo-ex`\n\n## Testing\n\ndebug: `cargo test --test lib`\n\nrelease: `cargo test --test lib --release`\n\nGo Rusketeers!\nThe power is yours!\n\n[`include-flate`]: https://crates.io/crates/include-flate\n[`globset`]: https://crates.io/crates/globset\n","funding_links":[],"categories":["Rust","Libraries","库 Libraries","server"],"sub_categories":["Web programming","网络编程 Web programming"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyrossh%2Frust-embed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyrossh%2Frust-embed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyrossh%2Frust-embed/lists"}