Modernize CI (#311)

Switches our CI from Travis-CI to Github Actions. At the same time this also turns on clippy and rustfmt linting.
This commit is contained in:
Lena Hellström 2020-03-24 14:33:13 -07:00 committed by GitHub
parent ae8c162d49
commit 8839b0600d
9 changed files with 124 additions and 58 deletions

95
.github/workflows/rust.yml vendored Normal file
View File

@ -0,0 +1,95 @@
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
check:
name: Check
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
rust:
- stable
- beta
- nightly
- 1.18.0 # MSRV
steps:
- uses: actions/checkout@v2
name: Checkout
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
name: Install Rust ${{ matrix.rust }}
- uses: actions-rs/cargo@v1
with:
command: check
name: Run `cargo check`
- uses: actions-rs/cargo@v1
with:
command: check
args: --examples
name: Check examples
if: matrix.rust != '1.18.0'
test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
rust:
- stable
- beta
- nightly
steps:
- uses: actions/checkout@v2
name: Checkout
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: ${{ matrix.rust }}
override: true
name: Install Rust ${{ matrix.rust }}
- uses: actions-rs/cargo@v1
with:
command: test
name: Run `cargo test`
lints:
name: Lints
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Checkout
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt, clippy
name: Install Rust stable
- uses: actions-rs/cargo@v1
with:
command: fmt
args: --all -- --check
name: Run `cargo fmt`
- uses: actions-rs/cargo@v1
with:
command: clippy
args: -- -D warnings
name: Run `cargo clippy`

View File

@ -1,16 +0,0 @@
language: rust
rust:
- stable
- beta
- nightly
script:
- cargo test
- cargo package
- cd target/package/bincode-* && cargo test
matrix:
include:
- rust: 1.18.0
script: cargo build

View File

@ -2,7 +2,7 @@
<img align="right" src="./logo.png" />
[![Build Status](https://travis-ci.com/servo/bincode.svg)](https://travis-ci.com/servo/bincode)
![CI](https://github.com/servo/bincode/workflows/CI/badge.svg)
[![](https://meritbadge.herokuapp.com/bincode)](https://crates.io/crates/bincode)
[![](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)

View File

@ -125,7 +125,7 @@ impl<O: Options, E: ByteOrder> WithOtherEndian<O, E> {
#[inline(always)]
pub(crate) fn new(options: O) -> WithOtherEndian<O, E> {
WithOtherEndian {
options: options,
options,
_endian: PhantomData,
}
}

View File

@ -32,10 +32,7 @@ pub(crate) struct Deserializer<R, O: Options> {
impl<'de, R: BincodeRead<'de>, O: Options> Deserializer<R, O> {
/// Creates a new Deserializer with a given `Read`er and a size_limit.
pub(crate) fn new(r: R, options: O) -> Deserializer<R, O> {
Deserializer {
reader: r,
options: options,
}
Deserializer { reader: r, options }
}
fn read_bytes(&mut self, count: u64) -> Result<()> {
@ -149,7 +146,7 @@ where
let mut buf = [0u8; 4];
// Look at the first byte to see how many bytes must be read
let _ = self.reader.read_exact(&mut buf[..1])?;
self.reader.read_exact(&mut buf[..1])?;
let width = utf8_char_width(buf[0]);
if width == 1 {
return visitor.visit_char(buf[0] as char);
@ -163,9 +160,9 @@ where
}
let res = str::from_utf8(&buf[..width])
.ok()
.and_then(|s| s.chars().next())
.ok_or(error())?;
.ok()
.and_then(|s| s.chars().next())
.ok_or_else(error)?;
visitor.visit_char(res)
}
@ -251,10 +248,8 @@ where
{
if self.len > 0 {
self.len -= 1;
let value = serde::de::DeserializeSeed::deserialize(
seed,
&mut *self.deserializer,
)?;
let value =
serde::de::DeserializeSeed::deserialize(seed, &mut *self.deserializer)?;
Ok(Some(value))
} else {
Ok(None)
@ -268,7 +263,7 @@ where
visitor.visit_seq(Access {
deserializer: self,
len: len,
len,
})
}
@ -313,10 +308,8 @@ where
{
if self.len > 0 {
self.len -= 1;
let key = serde::de::DeserializeSeed::deserialize(
seed,
&mut *self.deserializer,
)?;
let key =
serde::de::DeserializeSeed::deserialize(seed, &mut *self.deserializer)?;
Ok(Some(key))
} else {
Ok(None)
@ -327,10 +320,7 @@ where
where
V: serde::de::DeserializeSeed<'de>,
{
let value = serde::de::DeserializeSeed::deserialize(
seed,
&mut *self.deserializer,
)?;
let value = serde::de::DeserializeSeed::deserialize(seed, &mut *self.deserializer)?;
Ok(value)
}
@ -343,7 +333,7 @@ where
visitor.visit_map(Access {
deserializer: self,
len: len,
len,
})
}

View File

@ -1,6 +1,6 @@
use error::Result;
use serde;
use std::{io, slice};
use std::io;
/// An optional Read trait for advanced Bincode usage.
///
@ -77,13 +77,13 @@ impl<'storage> io::Read for SliceReader<'storage> {
let (read_slice, remaining) = self.slice.split_at(out.len());
out.copy_from_slice(read_slice);
self.slice = remaining;
Ok(out.len())
}
#[inline(always)]
fn read_exact(&mut self, out: &mut [u8]) -> io::Result<()> {
self.read(out).map(|_|())
self.read(out).map(|_| ())
}
}
@ -101,10 +101,10 @@ impl<R: io::Read> io::Read for IoReader<R> {
impl<'storage> SliceReader<'storage> {
#[inline(always)]
fn unexpected_eof() -> Box<::ErrorKind> {
return Box::new(::ErrorKind::Io(io::Error::new(
Box::new(::ErrorKind::Io(io::Error::new(
io::ErrorKind::UnexpectedEof,
"",
)));
)))
}
}

View File

@ -1,4 +1,5 @@
#![deny(missing_docs)]
#![allow(unknown_lints, bare_trait_objects, deprecated)]
//! Bincode is a crate for encoding and decoding using a tiny binary
//! serialization strategy. Using it, you can easily go from having

View File

@ -224,10 +224,6 @@ pub(crate) struct SizeChecker<O: Options> {
}
impl<O: Options> SizeChecker<O> {
pub fn new(options: O) -> SizeChecker<O> {
SizeChecker { options: options }
}
fn add_raw(&mut self, size: u64) -> Result<()> {
self.options.limit().add(size)
}
@ -755,7 +751,7 @@ fn encode_utf8(c: char) -> EncodeUtf8 {
buf[3] = (code & 0x3F) as u8 | TAG_CONT;
0
};
EncodeUtf8 { buf: buf, pos: pos }
EncodeUtf8 { buf, pos }
}
struct EncodeUtf8 {

View File

@ -334,12 +334,10 @@ fn test_serialized_size_bounded() {
assert!(config().limit(7).serialized_size(&0u64).is_err());
assert!(config().limit(7).serialized_size(&"").is_err());
assert!(config().limit(8 + 0).serialized_size(&"a").is_err());
assert!(
config()
.limit(8 + 3 * 4 - 1)
.serialized_size(&vec![0u32, 1u32, 2u32])
.is_err()
);
assert!(config()
.limit(8 + 3 * 4 - 1)
.serialized_size(&vec![0u32, 1u32, 2u32])
.is_err());
}
#[test]
@ -423,7 +421,8 @@ fn test_oom_protection() {
.serialize(&FakeVec {
len: 0xffffffffffffffffu64,
byte: 1,
}).unwrap();
})
.unwrap();
let y: Result<Vec<u8>> = config()
.limit(10)
.deserialize_from(&mut Cursor::new(&x[..]));
@ -581,7 +580,8 @@ fn test_zero_copy_parse_deserialize_into() {
slice: &encoded[..],
},
&mut target,
).unwrap();
)
.unwrap();
assert_eq!(target, f);
}
}