~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


44e80818 Peter

7 years ago
Merge pull request #43 from lukad/cargo-fmt
Files changed (3) hide show
  1. appveyor.yml +3 -0
  2. examples/rocket.rs +6 -20
  3. rustfmt.toml +1 -1
appveyor.yml CHANGED
@@ -107,6 +107,8 @@ install:
107
107
  - appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
108
108
  - rustup-init -yv --default-toolchain %channel% --default-host %target%
109
109
  - set PATH=%PATH%;%USERPROFILE%\.cargo\bin
110
+ - rustup install nightly
111
+ - rustup component add rustfmt-preview --toolchain nightly
110
112
  - if defined MSYS_BITS set PATH=C:\msys64\mingw%MSYS_BITS%\bin;C:\msys64\usr\bin;%PATH%
111
113
  - rustc -vV
112
114
  - cargo -vV
@@ -121,6 +123,7 @@ build: false
121
123
  #directly or perform other testing commands. Rust will automatically be placed in the PATH
122
124
  # environment variable.
123
125
  test_script:
126
+ - cargo +nightly fmt --all -- --check
124
127
  - cargo test --test lib
125
128
  - cargo test --test lib --release
126
129
  - cargo build --example basic
examples/rocket.rs CHANGED
@@ -5,11 +5,11 @@ extern crate rocket_contrib;
5
5
  #[macro_use]
6
6
  extern crate rust_embed;
7
7
 
8
+ use rocket::http::{ContentType, Status};
8
- use std::path::PathBuf;
9
+ use rocket::response;
9
10
  use std::ffi::OsStr;
10
11
  use std::io::Cursor;
11
- use rocket::response;
12
+ use std::path::PathBuf;
12
- use rocket::http::{ContentType, Status};
13
13
 
14
14
  #[derive(RustEmbed)]
15
15
  #[folder = "examples/public/"]
@@ -19,32 +19,18 @@ struct Asset;
19
19
  fn index<'r>() -> response::Result<'r> {
20
20
  Asset::get("index.html").map_or_else(
21
21
  || Err(Status::NotFound),
22
- |d| {
23
- response::Response::build()
22
+ |d| response::Response::build().header(ContentType::HTML).sized_body(Cursor::new(d)).ok(),
24
- .header(ContentType::HTML)
25
- .sized_body(Cursor::new(d))
26
- .ok()
27
- },
28
23
  )
29
24
  }
30
25
 
31
26
  #[get("/dist/<file..>")]
32
27
  fn dist<'r>(file: PathBuf) -> response::Result<'r> {
33
28
  let filename = file.display().to_string();
34
- let ext = file
35
- .as_path()
36
- .extension()
37
- .and_then(OsStr::to_str)
38
- .expect("Could not get file extension");
29
+ let ext = file.as_path().extension().and_then(OsStr::to_str).expect("Could not get file extension");
39
30
  let content_type = ContentType::from_extension(ext).expect("Could not get file content type");
40
31
  Asset::get(&filename.clone()).map_or_else(
41
32
  || Err(Status::NotFound),
42
- |d| {
43
- response::Response::build()
33
+ |d| response::Response::build().header(content_type).sized_body(Cursor::new(d)).ok(),
44
- .header(content_type)
45
- .sized_body(Cursor::new(d))
46
- .ok()
47
- },
48
34
  )
49
35
  }
50
36
 
rustfmt.toml CHANGED
@@ -6,4 +6,4 @@ fn_args_density = "Compressed"
6
6
  max_width = 160
7
7
  tab_spaces = 2
8
8
  indent_style = "Block"
9
- reorder_imported_names = true
9
+ reorder_imports = true