Skip to content

Commit

Permalink
Run rustfmt on Travis
Browse files Browse the repository at this point in the history
  • Loading branch information
stasm committed Oct 16, 2017
1 parent 9fa3c0a commit 90389cb
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 40 deletions.
15 changes: 7 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,15 @@ addons:
- kalakris-cmake

before_script:
- |
cargo install --force cargo-travis &&
export PATH=$HOME/.cargo/bin:$PATH
- cargo install --force cargo-travis
- export PATH=$HOME/.cargo/bin:$PATH
- which rustfmt || cargo install rustfmt

# the main build
script:
- |
cargo build &&
cargo test &&
cargo doc
- cargo fmt -- --write-mode=diff
- cargo build
- cargo test
- cargo doc

after_success:
# measure code coverage and upload to coveralls.io
Expand Down
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ extern crate fluent;

use fluent::MessageContext;

let ctx = MessageContext::new(&["en-US"]);
ctx.add_messages("hello-world = Hello, world!");
fn main() {
let mut ctx = MessageContext::new(&["en-US"]);
ctx.add_messages("hello-world = Hello, world!");

let value = ctx.get_message("hello-world")
.and_then(|message| ctx.format(message, None));
let value = ctx.get_message("hello-world").and_then(|message| {
ctx.format(message, None)
});

assert_eq!(value, Some("Hello, world!".to_string()));
assert_eq!(value, Some("Hello, world!".to_string()));
}
```


Expand All @@ -64,7 +67,11 @@ Local Development
cargo build
cargo test
cargo bench
cargo run --example simple
cargo run --example hello

When submitting a PR please use [`cargo fmt`][] (stable).

[`cargo fmt`]: https://github.com/rust-lang-nursery/rustfmt


Learn the FTL syntax
Expand Down
38 changes: 17 additions & 21 deletions benches/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn read_file(path: &str) -> Result<String, io::Error> {
fn bench_simple_parse(b: &mut Bencher) {
let source = read_file("./benches/simple.ftl").expect("Couldn't load file");

b.iter(|| { parse(&source).unwrap(); });
b.iter(|| parse(&source).unwrap());
}

#[bench]
Expand All @@ -43,11 +43,9 @@ fn bench_simple_format(b: &mut Bencher) {
let mut ctx = MessageContext::new(&["x-testing"]);
ctx.add_messages(&source);

b.iter(|| {
for id in &ids {
if let Some(message) = ctx.get_message(id.as_str()) {
let _value = ctx.format(message, None);
}
b.iter(|| for id in &ids {
if let Some(message) = ctx.get_message(id.as_str()) {
let _value = ctx.format(message, None);
}
});
}
Expand All @@ -56,7 +54,7 @@ fn bench_simple_format(b: &mut Bencher) {
fn bench_menubar_parse(b: &mut Bencher) {
let source = read_file("./benches/menubar.ftl").expect("Couldn't load file");

b.iter(|| { parse(&source).unwrap(); });
b.iter(|| parse(&source).unwrap());
}

#[bench]
Expand All @@ -76,20 +74,18 @@ fn bench_menubar_format(b: &mut Bencher) {
let mut ctx = MessageContext::new(&["x-testing"]);
ctx.add_messages(&source);

b.iter(|| {
for id in &ids {
// In real-life usage we'd have different fallback strategies for missing messages
// depending on the type of the widget this message was supposed to translate. Some
// widgets may only expect attributes and they shouldn't be forced to display a value.
// Here however it doesn't matter because we know for certain that the message for `id`
// exists.
if let Some(message) = ctx.get_message(id.as_str()) {
let _value = ctx.format(message, None);

if let Some(ref attributes) = message.attributes {
for attr in attributes {
let _value = ctx.format(attr, None);
}
b.iter(|| for id in &ids {
// In real-life usage we'd have different fallback strategies for missing messages
// depending on the type of the widget this message was supposed to translate. Some
// widgets may only expect attributes and they shouldn't be forced to display a value.
// Here however it doesn't matter because we know for certain that the message for `id`
// exists.
if let Some(message) = ctx.get_message(id.as_str()) {
let _value = ctx.format(message, None);

if let Some(ref attributes) = message.attributes {
for attr in attributes {
let _value = ctx.format(attr, None);
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions examples/hello.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
extern crate fluent;

use fluent::MessageContext;

fn main() {
let mut ctx = MessageContext::new(&["en-US"]);
ctx.add_messages("hello-world = Hello, world!");

let value = ctx.get_message("hello-world").and_then(|message| {
ctx.format(message, None)
});

assert_eq!(value, Some("Hello, world!".to_string()));
}
7 changes: 2 additions & 5 deletions src/intl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,8 @@ pub struct PluralRules {

impl PluralRules {
pub fn new(locales: &[&str]) -> PluralRules {
let supported = negotiate_languages(
locales,
LOCALES,
Some("en"),
&NegotiationStrategy::Lookup);
let supported =
negotiate_languages(locales, LOCALES, Some("en"), &NegotiationStrategy::Lookup);

let locale = supported[0].to_owned();
let f = match get_plural_rule(supported[0]) {
Expand Down

0 comments on commit 90389cb

Please sign in to comment.