Skip to content

Commit

Permalink
Format with rustfmt (#389)
Browse files Browse the repository at this point in the history
* Format with rustfmt

* Add rustfmt check to CI
  • Loading branch information
taiki-e authored May 22, 2020
1 parent 5e93fa4 commit 1fbf838
Show file tree
Hide file tree
Showing 27 changed files with 410 additions and 331 deletions.
9 changes: 5 additions & 4 deletions azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ pr: ["master"]

jobs:
# Check formatting
# - template: ci/azure-rustfmt.yml
# parameters:
# name: rustfmt
- template: ci/azure-rustfmt.yml
parameters:
name: rustfmt
rust_version: stable

# Apply clippy lints
# - template: ci/azure-clippy.yml
Expand Down Expand Up @@ -60,7 +61,7 @@ jobs:
- template: ci/azure-deploy-docs.yml
parameters:
dependsOn:
# - rustfmt
- rustfmt
# - clippy
- stable
- nightly
Expand Down
2 changes: 1 addition & 1 deletion benches/buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

extern crate test;

use test::Bencher;
use bytes::Buf;
use test::Bencher;

/// Dummy Buf implementation
struct TestBuf {
Expand Down
5 changes: 3 additions & 2 deletions benches/bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

extern crate test;

use test::Bencher;
use bytes::Bytes;
use test::Bencher;

#[bench]
fn deref_unique(b: &mut Bencher) {
Expand Down Expand Up @@ -42,7 +42,8 @@ fn deref_static(b: &mut Bencher) {

#[bench]
fn clone_static(b: &mut Bencher) {
let bytes = Bytes::from_static("hello world 1234567890 and have a good byte 0987654321".as_bytes());
let bytes =
Bytes::from_static("hello world 1234567890 and have a good byte 0987654321".as_bytes());

b.iter(|| {
for _ in 0..1024 {
Expand Down
39 changes: 28 additions & 11 deletions benches/bytes_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

extern crate test;

use test::Bencher;
use bytes::{BufMut, BytesMut};
use test::Bencher;

#[bench]
fn alloc_small(b: &mut Bencher) {
Expand All @@ -29,7 +29,6 @@ fn alloc_big(b: &mut Bencher) {
})
}


#[bench]
fn deref_unique(b: &mut Bencher) {
let mut buf = BytesMut::with_capacity(4096);
Expand Down Expand Up @@ -92,7 +91,9 @@ fn deref_two(b: &mut Bencher) {

#[bench]
fn clone_frozen(b: &mut Bencher) {
let bytes = BytesMut::from(&b"hello world 1234567890 and have a good byte 0987654321"[..]).split().freeze();
let bytes = BytesMut::from(&b"hello world 1234567890 and have a good byte 0987654321"[..])
.split()
.freeze();

b.iter(|| {
for _ in 0..1024 {
Expand Down Expand Up @@ -137,7 +138,9 @@ fn fmt_write(b: &mut Bencher) {
b.iter(|| {
let _ = write!(buf, "{}", s);
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
})
}

Expand All @@ -152,7 +155,9 @@ fn bytes_mut_extend(b: &mut Bencher) {
buf.extend(&data);
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}

Expand All @@ -169,7 +174,9 @@ fn put_slice_bytes_mut(b: &mut Bencher) {
buf.put_slice(&data);
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}

Expand All @@ -184,7 +191,9 @@ fn put_u8_bytes_mut(b: &mut Bencher) {
buf.put_u8(b'x');
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}

Expand All @@ -199,7 +208,9 @@ fn put_slice_vec(b: &mut Bencher) {
buf.put_slice(&data);
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}

Expand All @@ -214,7 +225,9 @@ fn put_u8_vec(b: &mut Bencher) {
buf.put_u8(b'x');
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}

Expand All @@ -229,7 +242,9 @@ fn put_slice_vec_extend(b: &mut Bencher) {
buf.extend_from_slice(&data);
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}

Expand All @@ -244,6 +259,8 @@ fn put_u8_vec_push(b: &mut Bencher) {
buf.push(b'x');
}
test::black_box(&buf);
unsafe { buf.set_len(0); }
unsafe {
buf.set_len(0);
}
});
}
13 changes: 13 additions & 0 deletions ci/azure-rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
jobs:
# Check formatting
- job: ${{ parameters.name }}
displayName: Check rustfmt
pool:
vmImage: ubuntu-16.04
steps:
- template: azure-install-rust.yml
parameters:
rust_version: ${{ parameters.rust_version }}
- script: |
cargo fmt --all -- --check
displayName: Check formatting
Loading

0 comments on commit 1fbf838

Please sign in to comment.