Skip to content

Commit

Permalink
Merge pull request #20 from Mcat12/feature/stable-rust
Browse files Browse the repository at this point in the history
Compile on stable Rust versions
  • Loading branch information
pyros2097 authored Jun 1, 2018
2 parents dad74ef + 306ff0e commit 4ef3a1d
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 36 deletions.
14 changes: 7 additions & 7 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
language: rust
sudo: false
dist: trusty
rust:
- stable
- nightly

cache:
cargo: true

matrix:
include:
- rust: nightly
allow_failures:
- rust: nightly

script:
- |
cargo clean
cargo test --tests --lib
cargo test --tests --lib --release
cargo clean
cargo test --lib
cargo test --lib --release
cargo build --example basic
cargo clean
cargo build --release --example basic
10 changes: 7 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ syn = "0.11"
quote = "0.3"
walkdir = "2.1.4"

rocket = { version = "0.3.6", optional = true }
rocket_codegen = { version = "0.3.6", optional = true }
rocket_contrib = { version = "0.3.6", optional = true }

[dev-dependencies]
rocket = "0.3.6"
rocket_codegen = "0.3.6"
rocket_contrib = "0.3.6"
rouille = "2.1.0"
fern = "0.5"

[features]
nightly = ["rocket", "rocket_codegen", "rocket_contrib"]

[badges]
appveyor = { repository = "pyros2097/rust-embed" }
travis-ci = { repository = "pyros2097/rust-embed" }
Expand Down
3 changes: 1 addition & 2 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
#![feature(attr_literals)]
#[macro_use]
extern crate rust_embed;

#[derive(RustEmbed)]
#[folder("examples/public/")]
#[folder = "examples/public/"]
struct Asset;

fn main() {
Expand Down
4 changes: 2 additions & 2 deletions examples/rocket.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(test, plugin, decl_macro, attr_literals)]
#![feature(test, plugin, decl_macro)]
#![plugin(rocket_codegen)]
extern crate rocket;
extern crate rocket_contrib;
Expand All @@ -12,7 +12,7 @@ use rocket::response;
use rocket::http::{ContentType, Status};

#[derive(RustEmbed)]
#[folder("examples/public/")]
#[folder = "examples/public/"]
struct Asset;

#[get("/")]
Expand Down
14 changes: 7 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,18 @@ rust-embed="2.0.0"
## Documentation
Declare a struct name it Asset or something and add an attribute `folder` to it which has the path to your static folder.
```rust
#![feature(attr_literals)]

#[derive(RustEmbed)]
#[folder("examples/public/")]
#[folder = "examples/public/"]
struct Asset;
```

## Usage
```rust
#![feature(attr_literals)]
#[macro_use]
extern crate rust_embed;
#[macro_use]
extern crate log;

#[derive(RustEmbed)]
#[folder("examples/public/")]
#[folder = "examples/public/"]
struct Asset;

fn main() {
Expand All @@ -46,6 +41,11 @@ To run the example in dev mode where it reads from the fs,
To run the example in release mode where it reads from binary,

`cargo run --release --example basic`

Note: To run the `rocket` example, add the `nightly` feature flag and run on a nightly build:

`cargo +nightly run --example rocket --features nightly`

## Testing
debug: `cargo test --tests --lib`

Expand Down
17 changes: 5 additions & 12 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
}

fn help() {
panic!("#[derive(RustEmbed)] should contain one attribute like this #[folder(\"examples/public/\")]");
panic!("#[derive(RustEmbed)] should contain one attribute like this #[folder = \"examples/public/\"]");
}

fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {
Expand All @@ -92,10 +92,10 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {
help();
}
let value = &ast.attrs[0].value;
let items = match value {
&MetaItem::List(ref attr_name, ref items) => {
let literal_value = match value {
&MetaItem::NameValue(ref attr_name, ref value) => {
if attr_name == "folder" {
items
value
} else {
panic!("#[derive(RustEmbed)] attribute name must be folder");
}
Expand All @@ -104,14 +104,7 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {
panic!("#[derive(RustEmbed)] attribute name must be folder");
}
};
let item = &items[0];
let lit = match item {
&NestedMetaItem::Literal(ref l) => l,
_ => {
panic!("Hello");
}
};
let folder_path = match lit {
let folder_path = match literal_value {
&Lit::Str(ref val, _) => val.clone(),
_ => {
panic!("#[derive(RustEmbed)] attribute value must be a string literal");
Expand Down
5 changes: 2 additions & 3 deletions tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#![feature(attr_literals)]
#[macro_use]
extern crate rust_embed;

#[test]
#[cfg(debug_assertions)]
fn dev() {
#[derive(RustEmbed)]
#[folder("examples/public/")]
#[folder = "examples/public/"]
struct Asset;

match Asset::get("index.html") {
Expand All @@ -27,7 +26,7 @@ fn dev() {
#[cfg(not(debug_assertions))]
fn prod() {
#[derive(RustEmbed)]
#[folder("examples/public/")]
#[folder = "examples/public/"]
struct Asset;

match Asset::get("index.html") {
Expand Down

0 comments on commit 4ef3a1d

Please sign in to comment.