Skip to content

Commit

Permalink
Enable stable support 🎉 (#219)
Browse files Browse the repository at this point in the history
Infer whether nightly features are available using rustc_version. If this fails, assume stable.

Closes #214
  • Loading branch information
lambda-fairy authored Sep 28, 2020
1 parent d66c2d6 commit 250d93d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 33 deletions.
18 changes: 6 additions & 12 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,7 @@ jobs:
- |
RUN_CLIPPY=true
rustup component add clippy --toolchain=nightly || RUN_CLIPPY=false
# As of right now, these need to be tested individually becuase `--workspace`
# (which is implied by `workspace = true`) cannot be used with `--features`
# This _may_ be resolved with the `--package` flag, however this requires
# opting in to a `-Z` unstable feature as of time of commit.
#
# Follow https://github.com/rust-lang/cargo/issues/5364 for updates.
- cargo test --manifest-path maud/Cargo.toml --features actix-web,iron,rocket
- cargo test --manifest-path maud_htmlescape/Cargo.toml
- cargo test --manifest-path maud_macros/Cargo.toml
- cargo test --all --all-features
- |
if $RUN_CLIPPY; then
CLIPPY_STATUS=0
Expand All @@ -26,12 +18,14 @@ jobs:
done
(exit $CLIPPY_STATUS)
fi
- name: "Unstable"
- name: "Stable"
rust: stable
script:
- cargo test --all --all-features
# Skip `--all-features` because stable Rocket isn't released yet
- cargo test --all
- name: "Benchmarks"
script:
- (cd benchmarks && cargo test --benches --features unstable)
- (cd benchmarks && cargo test --benches)
- name: "Documentation"
script:
- (cd docs && make -j$(nproc))
Expand Down
9 changes: 0 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,9 @@

Maud is an HTML template engine for Rust. It's implemented as a macro, `html!`, which compiles your markup to specialized Rust code. This unique approach makes Maud templates blazing fast, super type-safe, and easy to deploy.

Note that Maud depends on the unstable [procedural macro API][rustissue], and so requires the nightly version of Rust.

For more info on Maud, see the [official book][book].

[book]: https://maud.lambda.xyz/
[booksrc]: https://github.com/lambda-fairy/maud/tree/master/docs
[apiref]: https://docs.rs/maud/
[changelog]: https://github.com/lambda-fairy/maud/blob/master/CHANGELOG.md
[rustissue]: https://github.com/rust-lang/rust/issues/38356

## Stability

As of version 0.11, I am satisfied with the core syntax and semantics of the library. Development at this stage is focused on adding features and fixing bugs.

The underlying procedural macro API is still unstable though, so updating your compiler may break things. Please file an issue when this happens!
3 changes: 0 additions & 3 deletions benchmarks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@ version = "0.1.2"
authors = ["Chris Wong <[email protected]>"]
edition = "2018"

[features]
unstable = ["maud/unstable"]

[dependencies]
maud = { path = "../maud" }
handlebars = "*"
Expand Down
6 changes: 3 additions & 3 deletions maud/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ default = []
# Web framework integrations
actix-web = ["actix-web-dep", "futures"]

# Unstable features
unstable = []

[dependencies]
maud_htmlescape = { version = "0.17.0", path = "../maud_htmlescape" }
maud_macros = { version = "0.22.0", path = "../maud_macros" }
Expand All @@ -28,6 +25,9 @@ rocket = { version = ">= 0.3, < 0.5", optional = true }
futures = { version = "0.3.0", optional = true }
actix-web-dep = { version = "2.0.0", optional = true, default-features = false, package = "actix-web" }

[build-dependencies]
rustc_version = "0.2.3"

[dev-dependencies]
trybuild = { version = "1.0.33", features = ["diff"] }

Expand Down
8 changes: 8 additions & 0 deletions maud/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
use rustc_version::{version_meta, Channel};

fn main() {
match version_meta().map(|v| v.channel).unwrap_or(Channel::Stable) {
Channel::Dev | Channel::Nightly => println!("cargo:rustc-cfg=unstable"),
Channel::Beta | Channel::Stable => {}
}
}
10 changes: 5 additions & 5 deletions maud/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![cfg_attr(feature = "unstable", feature(min_specialization))]
#![cfg_attr(unstable, feature(min_specialization))]

//! A macro for writing HTML templates.
//!
Expand Down Expand Up @@ -78,28 +78,28 @@ pub trait Render {
}
}

#[cfg(not(feature = "unstable"))]
#[cfg(not(unstable))]
impl<T: fmt::Display + ?Sized> Render for T {
fn render_to(&self, w: &mut String) {
let _ = write!(Escaper::new(w), "{}", self);
}
}

#[cfg(feature = "unstable")]
#[cfg(unstable)]
impl<T: fmt::Display + ?Sized> Render for T {
default fn render_to(&self, w: &mut String) {
let _ = write!(Escaper::new(w), "{}", self);
}
}

#[cfg(feature = "unstable")]
#[cfg(unstable)]
impl Render for String {
fn render_to(&self, w: &mut String) {
let _ = Escaper::new(w).write_str(self);
}
}

#[cfg(feature = "unstable")]
#[cfg(unstable)]
impl Render for str {
fn render_to(&self, w: &mut String) {
let _ = Escaper::new(w).write_str(self);
Expand Down
3 changes: 3 additions & 0 deletions maud/tests/errors.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
// Diagnostics look slightly different on stable Rust
#![cfg(unstable)]

use trybuild::TestCases;

#[test]
Expand Down
1 change: 0 additions & 1 deletion rust-toolchain

This file was deleted.

0 comments on commit 250d93d

Please sign in to comment.