From 8a205d8e22465b494c1cf7a02d8fe1034f044df2 Mon Sep 17 00:00:00 2001 From: lzutao Date: Sun, 7 Apr 2019 01:41:44 +0700 Subject: [PATCH] Upgrade to 2018 edition (#49) * cargo +nightly fix --edition --edition-idioms * Upgrade `scroll_derive` to 2018 edition * Remove build.rs script --- Cargo.toml | 1 + benches/bench.rs | 6 +----- build.rs | 8 -------- examples/data_ctx.rs | 2 -- scroll_derive/Cargo.toml | 1 + scroll_derive/examples/main.rs | 4 +--- scroll_derive/src/lib.rs | 8 +++----- scroll_derive/tests/tests.rs | 9 ++++----- src/ctx.rs | 14 ++++---------- src/greater.rs | 2 +- src/leb128.rs | 10 +++++----- src/lesser.rs | 2 +- src/lib.rs | 31 +++++++++++++------------------ src/pread.rs | 4 ++-- src/pwrite.rs | 4 ++-- 15 files changed, 39 insertions(+), 67 deletions(-) delete mode 100644 build.rs diff --git a/Cargo.toml b/Cargo.toml index 8b0346e..ec01c09 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ name = "scroll" version = "0.10.0" authors = ["m4b ", "Ted Mielczarek "] readme = "README.md" +edition = "2018" keywords = ["bytes", "endian", "immutable", "pread", "pwrite"] repository = "https://github.com/m4b/scroll" license = "MIT" diff --git a/benches/bench.rs b/benches/bench.rs index f3afc0e..53f415a 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -1,11 +1,7 @@ #![feature(test)] extern crate test; -extern crate byteorder; -extern crate scroll; -extern crate rayon; -//extern crate byteio; -use scroll::{Cread, Cwrite, Pread, Pwrite, IOread, IOwrite, LE}; +use scroll::{Cread, Pread, LE}; use test::black_box; #[bench] diff --git a/build.rs b/build.rs deleted file mode 100644 index cb3ae20..0000000 --- a/build.rs +++ /dev/null @@ -1,8 +0,0 @@ -extern crate rustc_version; -use rustc_version::{version, Version}; - -fn main() { - if version().unwrap() >= Version::parse("1.26.0").unwrap() { - println!("cargo:rustc-cfg=rust_1_26"); - } -} diff --git a/examples/data_ctx.rs b/examples/data_ctx.rs index fda5da4..a8e5652 100644 --- a/examples/data_ctx.rs +++ b/examples/data_ctx.rs @@ -1,5 +1,3 @@ -extern crate scroll; - use scroll::{ctx, Endian, Pread, BE}; #[derive(Debug)] diff --git a/scroll_derive/Cargo.toml b/scroll_derive/Cargo.toml index ca8f5fd..ddcbc8b 100644 --- a/scroll_derive/Cargo.toml +++ b/scroll_derive/Cargo.toml @@ -3,6 +3,7 @@ name = "scroll_derive" version = "0.10.0" authors = ["m4b ", "Ted Mielczarek "] readme = "README.md" +edition = "2018" keywords = ["derive", "macros", "pread", "pwrite", "bytes"] repository = "https://github.com/m4b/scroll_derive" license = "MIT" diff --git a/scroll_derive/examples/main.rs b/scroll_derive/examples/main.rs index e0955d5..3f2c721 100644 --- a/scroll_derive/examples/main.rs +++ b/scroll_derive/examples/main.rs @@ -1,6 +1,4 @@ -extern crate scroll; -#[macro_use] -extern crate scroll_derive; +use scroll_derive::{Pread, Pwrite, IOread, IOwrite, SizeWith}; #[derive(Debug, PartialEq, Pread, Pwrite, IOread, IOwrite, SizeWith)] #[repr(C)] diff --git a/scroll_derive/src/lib.rs b/scroll_derive/src/lib.rs index f2c3477..15fb4cb 100644 --- a/scroll_derive/src/lib.rs +++ b/scroll_derive/src/lib.rs @@ -2,9 +2,7 @@ extern crate proc_macro; extern crate proc_macro2; -#[macro_use] -extern crate quote; -extern crate syn; +use quote::quote; use proc_macro::TokenStream; @@ -31,7 +29,7 @@ fn impl_struct(name: &syn::Ident, fields: &syn::FieldsNamed) -> proc_macro2::Tok } } }).collect(); - + quote! { impl<'a> ::scroll::ctx::TryFromCtx<'a, ::scroll::Endian> for #name where #name: 'a { type Error = ::scroll::Error; @@ -89,7 +87,7 @@ fn impl_try_into_ctx(name: &syn::Ident, fields: &syn::FieldsNamed) -> proc_macro } } }).collect(); - + quote! { impl<'a> ::scroll::ctx::TryIntoCtx<::scroll::Endian> for &'a #name { type Error = ::scroll::Error; diff --git a/scroll_derive/tests/tests.rs b/scroll_derive/tests/tests.rs index d54f77e..c1e55c1 100644 --- a/scroll_derive/tests/tests.rs +++ b/scroll_derive/tests/tests.rs @@ -1,6 +1,7 @@ -extern crate scroll; -#[macro_use] -extern crate scroll_derive; +use scroll_derive::{Pread, Pwrite, SizeWith, IOread, IOwrite}; +use scroll::{Pread, Pwrite, Cread, Cwrite, LE}; + +use scroll::ctx::SizeWith; #[derive(Debug, PartialEq, Pread, Pwrite)] struct Data { @@ -8,8 +9,6 @@ struct Data { timestamp: f64, } -use scroll::{Pread, Pwrite, Cread, Cwrite, LE}; -use scroll::ctx::SizeWith; #[test] fn test_data (){ diff --git a/src/ctx.rs b/src/ctx.rs index e370c79..46bd835 100644 --- a/src/ctx.rs +++ b/src/ctx.rs @@ -52,8 +52,8 @@ use core::result; #[cfg(feature = "std")] use std::ffi::{CStr, CString}; -use error; -use endian::Endian; +use crate::error; +use crate::endian::Endian; /// A trait for measuring how large something is; for a byte sequence, it will be its length. pub trait MeasureWith { @@ -128,13 +128,13 @@ pub trait TryFromCtx<'a, Ctx: Copy = (), This: ?Sized = [u8]> where Self: 'a + S /// Writes `Self` into `This` using the context `Ctx` pub trait IntoCtx: Sized { - fn into_ctx(self, &mut This, ctx: Ctx); + fn into_ctx(self, _: &mut This, ctx: Ctx); } /// Tries to write `Self` into `This` using the context `Ctx` pub trait TryIntoCtx: Sized { type Error; - fn try_into_ctx(self, &mut This, ctx: Ctx) -> Result; + fn try_into_ctx(self, _: &mut This, ctx: Ctx) -> Result; } /// Gets the size of `Self` with a `Ctx`, and in `Self::Units`. Implementors can then call `Gread` related functions @@ -279,9 +279,7 @@ ctx_impl!(u32, 4); ctx_impl!(i32, 4); ctx_impl!(u64, 8); ctx_impl!(i64, 8); -#[cfg(rust_1_26)] ctx_impl!(u128, 16); -#[cfg(rust_1_26)] ctx_impl!(i128, 16); macro_rules! from_ctx_float_impl { @@ -325,9 +323,7 @@ into_ctx_impl!(u32, 4); into_ctx_impl!(i32, 4); into_ctx_impl!(u64, 8); into_ctx_impl!(i64, 8); -#[cfg(rust_1_26)] into_ctx_impl!(u128, 16); -#[cfg(rust_1_26)] into_ctx_impl!(i128, 16); macro_rules! into_ctx_float_impl { @@ -458,9 +454,7 @@ sizeof_impl!(u32); sizeof_impl!(i32); sizeof_impl!(u64); sizeof_impl!(i64); -#[cfg(rust_1_26)] sizeof_impl!(u128); -#[cfg(rust_1_26)] sizeof_impl!(i128); sizeof_impl!(f32); sizeof_impl!(f64); diff --git a/src/greater.rs b/src/greater.rs index c0f231e..7a33051 100644 --- a/src/greater.rs +++ b/src/greater.rs @@ -1,6 +1,6 @@ use core::ops::{Index, IndexMut, RangeFrom}; -use ctx::{FromCtx, IntoCtx}; +use crate::ctx::{FromCtx, IntoCtx}; /// Core-read - core, no_std friendly trait for reading basic traits from byte buffers. Cannot fail unless the buffer is too small, in which case an assert fires and the program panics. /// diff --git a/src/leb128.rs b/src/leb128.rs index 121be44..a53df97 100644 --- a/src/leb128.rs +++ b/src/leb128.rs @@ -1,9 +1,9 @@ use core::u8; use core::convert::{From, AsRef}; use core::result; -use Pread; -use ctx::TryFromCtx; -use error; +use crate::Pread; +use crate::ctx::TryFromCtx; +use crate::error; #[derive(Debug, PartialEq, Copy, Clone)] /// An unsigned leb128 integer @@ -56,7 +56,7 @@ impl Sleb128 { #[inline] /// Read a variable length i64 from `bytes` at `offset` pub fn read(bytes: &[u8], offset: &mut usize) -> error::Result { - use Pread; + use crate::Pread; let tmp = bytes.pread::(*offset)?; *offset += tmp.size(); Ok(tmp.into()) @@ -95,7 +95,7 @@ impl<'a> TryFromCtx<'a> for Uleb128 { type Error = error::Error; #[inline] fn try_from_ctx(src: &'a [u8], _ctx: ()) -> result::Result<(Self, usize), Self::Error> { - use pread::Pread; + use crate::pread::Pread; let mut result = 0; let mut shift = 0; let mut count = 0; diff --git a/src/lesser.rs b/src/lesser.rs index f7283d4..84cb000 100644 --- a/src/lesser.rs +++ b/src/lesser.rs @@ -1,5 +1,5 @@ use std::io::{Result, Read, Write}; -use ctx::{FromCtx, IntoCtx, SizeWith}; +use crate::ctx::{FromCtx, IntoCtx, SizeWith}; /// An extension trait to `std::io::Read` streams; this only deserializes simple types, like `u8`, `i32`, `f32`, `usize`, etc. /// diff --git a/src/lib.rs b/src/lib.rs index d01c222..3ac955a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -102,18 +102,18 @@ //! //! For example, suppose we have a datatype and we want to specify how to parse or serialize this datatype out of some arbitrary //! byte buffer. In order to do this, we need to provide a [TryFromCtx](trait.TryFromCtx.html) impl for our datatype. -//! +//! //! In particular, if we do this for the `[u8]` target, using the convention `(usize, YourCtx)`, you will automatically get access to //! calling `pread_with::` on arrays of bytes. -//! +//! //! ```rust //! use scroll::{self, ctx, Pread, BE, Endian}; -//! +//! //! struct Data<'a> { //! name: &'a str, //! id: u32, //! } -//! +//! //! // note the lifetime specified here //! impl<'a> ctx::TryFromCtx<'a, Endian> for Data<'a> { //! type Error = scroll::Error; @@ -126,7 +126,7 @@ //! Ok((Data { name: name, id: id }, *offset)) //! } //! } -//! +//! //! let bytes = b"UserName\x00\x01\x02\x03\x04"; //! let data = bytes.pread_with::(0, BE).unwrap(); //! assert_eq!(data.id, 0x01020304); @@ -139,12 +139,7 @@ #[cfg(feature = "derive")] #[allow(unused_imports)] -#[macro_use] -extern crate scroll_derive; - -#[cfg(feature = "derive")] -#[doc(hidden)] -pub use scroll_derive::*; +use scroll_derive::{Pread, Pwrite, SizeWith, IOread, IOwrite}; #[cfg(feature = "std")] extern crate core; @@ -159,14 +154,14 @@ mod leb128; #[cfg(feature = "std")] mod lesser; -pub use endian::*; -pub use pread::*; -pub use pwrite::*; -pub use greater::*; -pub use error::*; -pub use leb128::*; +pub use crate::endian::*; +pub use crate::pread::*; +pub use crate::pwrite::*; +pub use crate::greater::*; +pub use crate::error::*; +pub use crate::leb128::*; #[cfg(feature = "std")] -pub use lesser::*; +pub use crate::lesser::*; #[doc(hidden)] pub mod export { diff --git a/src/pread.rs b/src/pread.rs index 69459f2..64f85d4 100644 --- a/src/pread.rs +++ b/src/pread.rs @@ -1,8 +1,8 @@ use core::result; use core::ops::{Index, RangeFrom}; -use ctx::{TryFromCtx, MeasureWith}; -use error; +use crate::ctx::{TryFromCtx, MeasureWith}; +use crate::error; /// A very generic, contextual pread interface in Rust. Allows completely parallelized reads, as `Self` is immutable /// diff --git a/src/pwrite.rs b/src/pwrite.rs index 51e95b0..08aa829 100644 --- a/src/pwrite.rs +++ b/src/pwrite.rs @@ -1,8 +1,8 @@ use core::result; use core::ops::{Index, IndexMut, RangeFrom}; -use ctx::{TryIntoCtx, MeasureWith}; -use error; +use crate::ctx::{TryIntoCtx, MeasureWith}; +use crate::error; /// Writes into `Self` at an offset of type `I` using a `Ctx` ///