pyrossh / rust-embed Goto Github PK
View Code? Open in Web Editor NEWRust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
License: MIT License
Rust Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
License: MIT License
The actix example doesn't load any of the files from Asset
, it only shows "Hello World" :)
I want to embed the folder workspace/crate_foo/bar
, so I do:
#[derive(RustEmbed)]
#[folder = "crate_foo/bar"] // relative to workspace root
pub struct Assets;
But when I do cargo test
, it fails when the doc-tests are run:
# cargo test -p crate_foo
Compiling crate_foo v0.1.0 (/usr/src/workspace/crate_foo)
Finished dev [unoptimized + debuginfo] target(s) in 4.14s
Running target/debug/deps/crate_foo-ba8abb39df8832bd
running 2 tests
test [..] ... ok
test [..] ... ok
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
Doc-tests crate_foo
error: proc-macro derive panicked
--> /usr/src/workspace/crate_foo/src/templates.rs:50:14
|
50 | #[derive(RustEmbed)]
| ^^^^^^^^^
|
= help: message: #[derive(RustEmbed)] folder 'crate_foo/bar' does not exist. cwd: '/usr/src/workspace/crate_foo'
error: test failed, to rerun pass '--doc'
Because apparently, for normal tests, it uses cwd workspace
but for doc-tests, it uses cwd workspace/crate_foo
, so it will try to embed workspace/crate_foo/crate_foo/bar
when running doc-tests, but why?
I tried to use #[cfg(not(test))]
on a wrapper module to only conditionally embed the dir, but it doesn't work..
How can I make it work?
Is there a #[cfg(not(doc_tests))]
or something? How can I embed only when doc-tests aren't run?
Hi,
Given:
\ (the root of cargo workspace)
\Cargo.toml
\assets\ (a simple folder)
\component-a\ (a crate within the workspace)
\component-a\Cargo.toml
\component-a\assets
\static\ (a simple folder)
\static\assets
where each "\assets" directory is a copy with at least a.txt
in, then #[folder = "assets/"]
is the only one that works when used within \component-a
.
Observations:
#[folder = "component-a/assets"]
compiles but lists no files#[folder = "static/assets"]
compiles but lists no filesthis is regardless of whether cargo run
is run within \
or \component-a
.
What I am trying to achieve is either component-a/assets/
or static/assets/
.
Help :-)
This allocates a new Vec for every get() call:
https://github.com/pyros2097/rust-embed/blob/b509d63985c4079c0cd2aaf2e3c951ee249003d5/src/lib.rs#L62
It would be better to return a &'static [u8]
by writing this instead:
#key => Some(&include_bytes!(#canonical_path_str)[..]),
And then pub fn get(file_path: &str) -> Option<&'static [u8]> {
I have a base library which embeds some icons using rust-embed
. When using the library from another project the embedded resources can only be found when running the binary in release mode. Trying to run the application in debug mode where the resources are read from the file system yields run-time errors.
So I would like to turn on the debug-embed
feature to always embed the resource like in the release build.
However by doing this
rust-embed = { version = "4.2", features = ["debug-embed"] }
I get the following compile errors
|
9 | #[derive(RustEmbed)]
| ^^^^^^^^^ could not find `utils` in `rust_embed`
Any help would be greatly appreciated.
Hi, and thanks for developing this invaluable tool :)
I've got a bit of a problem. I'm serving the content of the embedded folder via actix-web
, and running a parcel watch
job for frontend development. This frontend tooling has autoreloading, so when the watch
job builds a new version of my frontend the page gets reloaded. This almost always results in only half of the javascript file getting served and the reload aborting because of it.
I don't know how rust-embed works internally, but I'm assuming this is because rust-embed reads the file at a time where it's not done being written?
Building on #90:
A common use case of rust-embed is web servers (e.g. desktop apps that embed a web server to render their UI in a browser view).
For web servers or anything that needs to read the embedded files as fast as possible and multiple times over the lifetime of the process, it makes sense to decompress each asset only once and then cache the result, so that further calls for the same path can return the cached/decompressed value immediately.
This could be another feature, e.g. cached-compression
which also enables the compression
feature when it is enabled.
For the memoization/caching of each asset we could use OnceCell
/Lazy
(or an Option
).
@Mcat12 What do you think? :)
Doc comments on the struct the derive is applied to cause rust-embed to panic
Sample code: https://github.com/lopopolo/rust-embed-panic
โถ cargo build
Compiling rust-embed-panic v0.1.0 (/Users/lopopolo/Desktop/rust-embed-panic)
error: proc-macro derive panicked
--> src/main.rs:7:10
|
7 | #[derive(RustEmbed)]
| ^^^^^^^^^
|
= help: message: #[derive(RustEmbed)] should contain one attribute like this #[folder = "examples/public/"]
error: aborting due to previous error
error: Could not compile `rust-embed-panic`.
To learn more, run the command again with --verbose.
https://github.com/pyros2097/rust-embed/blob/93bf8334488a8387ab419164aeabf7855ceda29d/src/lib.rs#L23
The trailing slash after dir should not be mandatory, for usability/convenience reasons!
This line should be changed to let name = &format!("{}/{}", folder_path, file_path);
(If the dir path already has a trailing slash, double slash won't be a problem. Or you could pass the slice up to the trailing slash.)
It would be nice to have a method such as fn list(&self) -> Vec<Path>
or fn list(&self) -> Vec<String>
to get a list of the available files. My use case is that I want to have a few specifications for different models of TVs, and rather than typing out the names of the models twice, I would just name the file describing the TV after the appropriate display option, and then retrieve that list in the program.
How about adding optional compression support, like include-flate?
After updating to verision 5.0.0 I get the following error, in multiple different codebases
error[E0463]: can't find crate for `rust_embed_utils`
--> src/main.rs:59:10
|
59 | #[derive(RustEmbed)]
| ^^^^^^^^^ can't find crate
The error is fixed by adding the following to Cargo.toml
so it seems like something is missing a dependency.
rust-embed-utils = "5.0.0"
rustc 1.36.0 (a53f9df32 2019-07-03)
cargo 1.36.0 (c4fcfb725 2019-05-15)
When building on windows the keys generated for the paths by the macro use \ as a path separator.
If the main use case for this crate is to embed web assets, then it could be usefull to replace \ with / when building on windows, or maybe easier when std::path::MAIN_SEPARATOR == '\\'
.
example:
error: proc-macro derive panicked
--> C:\Users\LUNA\.cargo\git\checkouts\pypack-071d8f8d2bc34e74\06f6da1\src\lib.rs:13:10
|
13 | #[derive(RustEmbed)]
| ^^^^^^^^^
|
= help: message: #[derive(RustEmbed)] folder 'dist/' does not exist. cwd: 'C:\Users\LUNA\.cargo\git\checkouts\pypack-071d8f8d2bc34e74\06f6da1'
I have the following code:
#[derive(RustEmbed)]
#[folder = "$OUT_DIR/gui/"]
struct GuiAsset;
And when I try to compile this I get the following error:
error: proc-macro derive panicked
--> src\gui.rs:47:10
|
47 | #[derive(RustEmbed)]
| ^^^^^^^^^
|
= help: message: #[derive(RustEmbed)] folder '$OUT_DIR/gui/' does not exist. cwd: 'E:\Repo\castle-game'
It looks like $OUT_DIR
isn't resolved properly, even though PR #67 should have fixed this.
I want to tranfer binary model file.
GET /weights/tiny_face_detector_model-shard1:
=> Matched: GET /<file..> (dist)
=> Outcome: Failure
=> Warning: Responding with 400 Could not get file extension catcher.
=> Response succeeded.
This would let me work around #34 like so:
The existing global functions could be implemented on top, by creating a global object that has the two directories fixed at compile time.
If I can find a way to do that, would you take a PR?
I noticed something when trying to use the git repo directly in Cargo.toml.
rust-embed = { git = "https://github.com/pyros2097/rust-embed" }
Compiling with Appveyor, the build errored out with this message:
Compiling rust-embed-impl v4.4.0 (https://github.com/pyros2097/rust-embed#de8e97fe)
error: expected item, found `..`
--> C:\Users\appveyor\.cargo\git\checkouts\rust-embed-88640eaf411660a2\de8e97f\impl\src\utils.rs:1:1
|
1 | ../../src/utils.rs
| ^^ expected item
error: aborting due to previous error
error: Could not compile `rust-embed-impl`.
The latest released version (v4.4.0) was building successfully.
Hello, I tried to use nuxt.js
and generated some static pages using nuxt generate
, while I load these files using a static file server it works perfectly but while I load it using rust-embed
it doesn't work anymore.
Do you have some ideas why it happens? I'll try to make a repro.
It'd be more idiomatic to use Path::strip_prefix here:
https://github.com/pyros2097/rust-embed/blob/de355d14b4edd86a5f8b33503344772345fadacc/src/lib.rs#L54
D:\3rdparty\rust-embed [master โก]> cargo run --example rocket
โ[0mโ[0mโ[1mโ[32m Updatingโ[0m registry `https://github.com/rust-lang/crates.io-index`
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m winapi v0.3.5
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m unicode-xid v0.0.4
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m quote v0.3.15
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m synom v0.11.3
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m syn v0.11.11
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m same-file v1.0.2
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m walkdir v2.1.4
โ[0mโ[0mโ[1mโ[32m Compilingโ[0m rust-embed v3.0.0 (file:///D:/3rdparty/rust-embed)
โ[0mโ[1mโ[38;5;9merror[E0463]โ[0mโ[0mโ[1mโ[38;5;15m: can't find crate for `rocket_codegen`โ[0m
โ[0m โ[0mโ[0mโ[1mโ[38;5;14m--> โ[0mโ[0mexamples\rocket.rs:2:11โ[0m
โ[0m โ[0mโ[0mโ[1mโ[38;5;14m|โ[0m
โ[0mโ[1mโ[38;5;14m2โ[0mโ[0m โ[0mโ[0mโ[1mโ[38;5;14m| โ[0mโ[0m#![plugin(rocket_codegen)]โ[0m
โ[0m โ[0mโ[0mโ[1mโ[38;5;14m| โ[0mโ[0m โ[0mโ[0mโ[1mโ[38;5;9m^^^^^^^^^^^^^^โ[0mโ[0m โ[0mโ[0mโ[1mโ[38;5;9mcan't f
ind crateโ[0m
โ[0mโ[1mโ[38;5;9merrorโ[0mโ[0mโ[1mโ[38;5;15m: aborting due to previous errorโ[0m
โ[0mโ[1mโ[38;5;15mFor more information about this error, try `rustc --explain E0463`.โ[0m
โ[0mโ[0mโ[1mโ[31merror:โ[0m Could not compile `rust-embed`.
To learn more, run the command again with --verbose.
Is it rust macro perhaps?
why don't you use the standard macros?
http://doc.rust-lang.org/std/macro.include_bytes!.html
http://doc.rust-lang.org/std/macro.include_str!.html
error[E0433]: failed to resolve: use of undeclared type or module `actix_web`
--> examples/actix.rs:1:5
|
1 | use actix_web::body::Body;
| ^^^^^^^^^ use of undeclared type or module `actix_web`
error[E0433]: failed to resolve: use of undeclared type or module `warp`
--> examples/warp.rs:2:5
|
2 | use warp::{http::header::HeaderValue, path::Tail, reply::Response, Filter, Rejection, Reply};
| ^^^^ use of undeclared type or module `warp`
error[E0432]: unresolved import `actix_web`
--> examples/actix.rs:2:5
|
2 | use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
| ^^^^^^^^^ use of undeclared type or module `actix_web`
error[E0432]: unresolved import `mime_guess`
--> examples/actix.rs:3:5
|
3 | use mime_guess::from_path;
| ^^^^^^^^^^ use of undeclared type or module `mime_guess`
error[E0433]: failed to resolve: use of undeclared type or module `actix_rt`
--> examples/actix.rs:34:3
|
34 | #[actix_rt::main]
| ^^^^^^^^ use of undeclared type or module `actix_rt`
error[E0412]: cannot find type `Body` in this scope
--> examples/actix.rs:15:17
|
15 | let body: Body = match content {
| ^^^^ not found in this scope
error[E0432]: unresolved import `warp`
--> examples/warp.rs:2:5
|
2 | use warp::{http::header::HeaderValue, path::Tail, reply::Response, Filter, Rejection, Reply};
| ^^^^ use of undeclared type or module `warp`
error[E0433]: failed to resolve: use of undeclared type or module `tokio`
--> examples/warp.rs:8:3
|
8 | #[tokio::main]
| ^^^^^ use of undeclared type or module `tokio`
error[E0433]: failed to resolve: use of undeclared type or module `warp`
--> examples/warp.rs:10:20
|
10 | let index_html = warp::path::end().and_then(serve_index);
| ^^^^ use of undeclared type or module `warp`
error[E0433]: failed to resolve: use of undeclared type or module `warp`
--> examples/warp.rs:11:14
|
11 | let dist = warp::path("dist").and(warp::path::tail()).and_then(serve);
| ^^^^ use of undeclared type or module `warp`
error[E0433]: failed to resolve: use of undeclared type or module `warp`
--> examples/warp.rs:11:37
|
11 | let dist = warp::path("dist").and(warp::path::tail()).and_then(serve);
| ^^^^ use of undeclared type or module `warp`
error[E0433]: failed to resolve: use of undeclared type or module `warp`
--> examples/warp.rs:14:3
|
14 | warp::serve(routes).run(([127, 0, 0, 1], 8080)).await;
| ^^^^ use of undeclared type or module `warp`
error[E0433]: failed to resolve: use of undeclared type or module `warp`
--> examples/warp.rs:26:43
|
26 | let asset = Asset::get(path).ok_or_else(warp::reject::not_found)?;
| ^^^^ use of undeclared type or module `warp`
error[E0433]: failed to resolve: use of undeclared type or module `mime_guess`
--> examples/warp.rs:27:14
|
27 | let mime = mime_guess::from_path(path).first_or_octet_stream();
| ^^^^^^^^^^ use of undeclared type or module `mime_guess`
error[E0433]: failed to resolve: use of undeclared type or module `Response`
--> examples/warp.rs:29:17
|
29 | let mut res = Response::new(asset.into());
| ^^^^^^^^ use of undeclared type or module `Response`
error[E0433]: failed to resolve: use of undeclared type or module `HeaderValue`
--> examples/warp.rs:30:44
|
30 | res.headers_mut().insert("content-type", HeaderValue::from_str(mime.as_ref()).unwrap());
| ^^^^^^^^^^^ use of undeclared type or module `HeaderValue`
error[E0412]: cannot find type `Tail` in this scope
--> examples/warp.rs:21:22
|
21 | async fn serve(path: Tail) -> Result<impl Reply, Rejection> {
| ^^^^ not found in this scope
error: aborting due to 12 previous errors
Some errors have detailed explanations: E0412, E0432, E0433.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `rust-embed`.
Caused by:
process didn't exit successfully: `/usr/bin/rustc --crate-name warp --edition=2018 examples/warp.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C opt-level=3 -C metadata=2deb8416ae26f1cb -C extra-filename=-2deb8416ae26f1cb --out-dir /home/brain/rpmbuild/BUILD/rust-embed-5.5.1/target/release/examples -L dependency=/home/brain/rpmbuild/BUILD/rust-embed-5.5.1/target/release/deps --extern rust_embed=/home/brain/rpmbuild/BUILD/rust-embed-5.5.1/target/release/deps/librust_embed-83b19ecfa2dd0123.rlib --extern rust_embed_impl=/home/brain/rpmbuild/BUILD/rust-embed-5.5.1/target/release/deps/librust_embed_impl-bf0e64a0f34f7c27.so --extern rust_embed_utils=/home/brain/rpmbuild/BUILD/rust-embed-5.5.1/target/release/deps/librust_embed_utils-48390f5cd9c5c672.rlib --extern walkdir=/home/brain/rpmbuild/BUILD/rust-embed-5.5.1/target/release/deps/libwalkdir-5b6b43cef122a702.rlib -Copt-level=3 -Cdebuginfo=2 -Clink-arg=-Wl,-z,relro,-z,now -Ccodegen-units=1 --cap-lints=warn` (exit code: 1)
warning: build failed, waiting for other jobs to finish...
error[E0277]: `main` has invalid return type `impl std::future::Future`
--> examples/actix.rs:35:20
|
35 | async fn main() -> std::io::Result<()> {
| ^^^^^^^^^^^^^^^^^^^ `main` can only return types that implement `std::process::Termination`
|
= help: consider using `()`, or a `Result`
error: aborting due to 6 previous errors
I did not try to reproduce this with upstream yet, but this is happening on Fedora with simple cargo test
.
Not included in the changelog are these PRs:
$crate
to improve macro hygiene.log
macros in debug mode. This caused errors if you didn't include the log macro in your crate, or if you used Rocket (they have some macros with the same names).use
statements in the debug code to not conflict with the other use
statements of the file the macro is used in.These are all useful to see in a changelog so that people can see what bugs each release fixed. Besides PRs, there are probably some missed changes you directly made without going through a PR.
Also missing are these versions:
When I use the macro in release mode to include a large file (I first tried with ~500 kB) it takes a very long time to compile. The culprit here is the huge vec![..]
literal which seems to be very expensive.
Using include_bytes!
would solve the problem because it's a compiler built-in that doesn't create a Vector and push one Byte at a time into it.
See my PR #16.
To reproduce run
dd if=/dev/urandom of=examples/public/index.html bs=1k count=500; time cargo run --release --example basic
The current macro only generates an impl {}
block; that is useful as it avoids a need to use
any traits to access the get
and iter
methods, but the lack of a trait prevents any generic extensions.
Defining & exporting a RustEmbed trait, and implementing it as part of the derive, could allow things like extension crates to handle the boilerplate of binding assets to different frameworks, path globbing extension methods, etc.
I wrote this code:
#[derive(RustEmbed)]
#[folder = "/$CARGO_MANIFEST_DIR/static"]
struct Asset;
fn main(){
let index_html = Asset::get("index.html").unwrap();
}
And got the below:
error: proc-macro derive panicked
--> src\main.rs:8:10
|
8 | #[derive(RustEmbed)]
| ^^^^^^^^^
|
= help: message: #[derive(RustEmbed)] folder 'C:/$CARGO_MANIFEST_DIR/static' does not exist. cwd: 'C:\Users\Yara Yousef\PycharmProjects\wv'
A variable has been detected. RustEmbed can expand variables when the `interpolate-folder-path` feature is enabled.
error[E0599]: no function or associated item named `get` found for struct `Asset` in the current scope
--> src\main.rs:13:29
|
10 | struct Asset;
| ------------- function or associated item `get` not found for this
I tried to run cargo install rust-embed
but it was not found.
This tools would be a nice complement to http://rocket.rs
I was just about to open a bug about how slow rust-embed was performing in release mode...
... then I found that I was accidentally embedding a 70Mb+ node_modules
directory. Oops. (Still, it did seem rather slow for a mere 70MB but maybe that's because it's a lot of small files?)
It would be nice if I could embed some directory, but exclude some large subdirectories from that embed. Ex:
#[derive(RustEmbed)]
#[folder = "examples/"]
#[exclude = "examples/big_dir"]
Or, you could make it respect .gitignores? I already had that node_modules
directory ignored, which is part of the reason I'd forgotten about it.
Otherwise, thanks for a great crate!
I'd a look at rocket example but my issue is different, I've the below code:
#![feature(decl_macro, proc_macro_hygiene)]
use rocket_contrib::templates::Template;
use rocket_contrib::serve::StaticFiles;
mod routes;
use rust_embed::RustEmbed;
#[derive(RustEmbed)]
#[folder = "static"]
struct Static;
#[derive(RustEmbed)]
#[folder = "templates"]
struct Templates;
fn main() {
rocket::ignite()
.attach(Template::fairing())
.mount("/static",
StaticFiles::from("static"))
.mount("/", rocket::routes![routes::root::root])
.launch();
}
And the app structure is as shown:
And my Cargo.toml
is:
[dependencies]
rust-embed = {version = "5.5.1", features = ["interpolate-folder-path"]}
rocket = "0.4.4"
[dependencies.rocket_contrib]
version = "0.4.4"
defaullt-features = "false"
features = ["tera_templates", "serve"]
Once I got the .exe
file generated at Win 10
it did not work without copying the static
and templates
folder in the same directory of the executable, am I missing something to get them embed in the binary itself?
From https://ci.appveyor.com/project/pyros2097/rust-embed/builds/21541868/job/xnkec8tem3kqw8bn :
cargo test --test lib
Updating crates.io index
error: failed to select a version for the requirement `ring = "^0.11.0"`
candidate versions found which didn't match: 0.14.0, 0.13.5, 0.8.1
location searched: crates.io index
required by package `cookie v0.9.1`
... which is depended on by `rocket v0.3.6`
... which is depended on by `rust-embed v4.3.0 (C:\projects\rust-embed)`
Command exited with code 101
Pretty sure this is not rust-embed's fault at all, but it interferes with the AppVeyor test.
The procmacro should give an error if the embedded dir doesn't exist, also in debug builds!
User should be able to specify a feature flag to control whether the resources should be embedded in binary or read from fs.
It would be nice with the default feature enable the binary mode in both debug and release version. After all this crate's purpose is embed resource into binary.
It would be nice to release a new version now that rust-embed got updated to use syn 1.x so that downstream users can get rid of syn 0.11 from their crate graph.
I noticed that subpaths on my Rocket projects that uses similar code to https://github.com/pyros2097/rust-embed/blob/master/examples/rocket.rs did not work on windows in release build (when files get embedded).
I fixed this by changing:
https://github.com/pyros2097/rust-embed/blob/3b1ac9f4d671af9cf2aa87a8cfd7f76dfa9b7641/examples/rocket.rs#L27
to
let filename = file.display().to_string().replace("\\", "/");
It now works on linux and windows in both release builds.
I also found this issue which looked similar but PR did not seem to solve this.
Try to run cargo run --example basic
from the examples
subfolder, it will crash.
The procmacro should make sure that it works, no matter where cargo is called from!
(Also important for workspaces, where the exe could be in the toplevel or in a sub folder.)
I haven't found any place which documents the changes in each version, so I assume the changes have never been documented besides the commit messages. It would be helpful to create a changelog file or use GitHub Releases to document the changes in each version.
There were a lot of versions published between 5.0.1 (last documented in changelog) to 5.1.0. The changelog should be updated with the changes these versions made.
Attempting to compile the following code results in a panic. If structs that derive RustEmbed
cannot have fields, the compiler should spit out an error message to help me fix the issue ๐
#[derive(RustEmbed)]
#[folder = "spec-runner/spec/mspec/"]
struct Sources {
v: bool,
}
$ cargo build
Compiling spec-runner v0.1.0 (/Users/lopopolo/dev/repos/ferrocarril/spec-runner)
error: proc-macro derive panicked
--> spec-runner/src/mspec.rs:22:10
|
22 | #[derive(RustEmbed)]
| ^^^^^^^^^
|
= help: message: #[derive(RustEmbed)] should contain one attribute like this #[folder = "examples/public/"]
error: aborting due to previous error
error: Could not compile `spec-runner`.
To learn more, run the command again with --verbose.
It seems many useful libraries like serde, diesel are working in stable rust right now. We should also move this to use stable rust so that it could be more in tune to work in production environments.
Here is the list of changes I can think of,
#![feature(attr_literals)]
It would be useful to know which methods can be called on the Asset
struct and which signatures they have. E.g. can get
only be called with a &str or also with a Path
?
EDIT: I looked at the source and it looks like get
can only be called with a &str, why not with a P: AsRef<Path>
(called with relative paths)?
Hi,
I'm trying to get the actix example working in it's own new project.
But I get the following error:
no method named as_ref
found for type mime_guess::Mime
in the current scope
src/main.rs:22:61
$ cargo build
Compiling embed_actix v0.1.0 (/home/rj/src/embed_actix)
error[E0599]: no method named `as_ref` found for type `mime_guess::Mime` in the current scope
--> src/main.rs:22:61
|
22 | HttpResponse::Ok().content_type(guess_mime_type(path).as_ref()).body(body)`
| ^^^^^
cargo.toml:
[package]
name = "embed_actix"
version = "0.1.0"
authors = ["me <[email protected]>"]
edition = "2018"
[dependencies]
actix-web = "0.7.19"
rust-embed = "4.4.0"
mime_guess = "1.8.7"
src/main.rs is copy of (with no changes):
examples/actix.rs
Mime is defined as
#[derive(Clone, Debug, Eq, Hash, Ord, PartialOrd)]
pub struct Mime<T: AsRef<[Param]> = Vec<Param>>(pub TopLevel, pub SubLevel, pub T);
so should have the as_ref trait?
Any help to get this working would be great - thanks!
rust-embed prints to stdout during compilation:
https://github.com/pyros2097/rust-embed/blob/2025bfb7b8becb4f281efa5cd3febc611ba98fcb/src/lib.rs#L56
macros should not do that.
It breaks editors that parse the json output:
rust-lang/rust-enhanced#310 (comment)
All occurrences of println
and eprintln
in that file should be removed.
When I run the sample application from the readme in release mode it doesn't work. when I put the folder example/public/ next to the release binary, it works
[fretn@machine embed]$ rustup show
Default host: x86_64-apple-darwin
installed toolchains
--------------------
stable-x86_64-apple-darwin
nightly-x86_64-apple-darwin
installed targets for active toolchain
--------------------------------------
x86_64-apple-darwin
x86_64-unknown-linux-musl
active toolchain
----------------
stable-x86_64-apple-darwin (default)
rustc 1.24.1 (d3ae9a9e0 2018-02-27)
[fretn@machine embed]$
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.