Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to 2018 edition #49

Merged
merged 3 commits into from
Apr 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "scroll"
version = "0.10.0"
authors = ["m4b <m4b.github.io@gmail.com>", "Ted Mielczarek <ted@mielczarek.org>"]
readme = "README.md"
edition = "2018"
keywords = ["bytes", "endian", "immutable", "pread", "pwrite"]
repository = "https://github.com/m4b/scroll"
license = "MIT"
Expand Down
6 changes: 1 addition & 5 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down
8 changes: 0 additions & 8 deletions build.rs

This file was deleted.

2 changes: 0 additions & 2 deletions examples/data_ctx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate scroll;

use scroll::{ctx, Endian, Pread, BE};

#[derive(Debug)]
Expand Down
1 change: 1 addition & 0 deletions scroll_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ name = "scroll_derive"
version = "0.10.0"
authors = ["m4b <m4b.github.io@gmail.com>", "Ted Mielczarek <ted@mielczarek.org>"]
readme = "README.md"
edition = "2018"
keywords = ["derive", "macros", "pread", "pwrite", "bytes"]
repository = "https://github.com/m4b/scroll_derive"
license = "MIT"
Expand Down
4 changes: 1 addition & 3 deletions scroll_derive/examples/main.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand Down
8 changes: 3 additions & 5 deletions scroll_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 4 additions & 5 deletions scroll_derive/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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 {
id: u32,
timestamp: f64,
}

use scroll::{Pread, Pwrite, Cread, Cwrite, LE};
use scroll::ctx::SizeWith;

#[test]
fn test_data (){
Expand Down
14 changes: 4 additions & 10 deletions src/ctx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Ctx> {
Expand Down Expand Up @@ -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<Ctx: Copy = (), This: ?Sized = [u8]>: 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<Ctx: Copy = (), This: ?Sized = [u8]>: Sized {
type Error;
fn try_into_ctx(self, &mut This, ctx: Ctx) -> Result<usize, Self::Error>;
fn try_into_ctx(self, _: &mut This, ctx: Ctx) -> Result<usize, Self::Error>;
}

/// Gets the size of `Self` with a `Ctx`, and in `Self::Units`. Implementors can then call `Gread` related functions
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/greater.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
10 changes: 5 additions & 5 deletions src/leb128.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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<i64> {
use Pread;
use crate::Pread;
let tmp = bytes.pread::<Sleb128>(*offset)?;
*offset += tmp.size();
Ok(tmp.into())
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/lesser.rs
Original file line number Diff line number Diff line change
@@ -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.
///
Expand Down
31 changes: 13 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<YourDatatype>` 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;
Expand All @@ -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::<Data>(0, BE).unwrap();
//! assert_eq!(data.id, 0x01020304);
Expand All @@ -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;
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions src/pread.rs
Original file line number Diff line number Diff line change
@@ -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
///
Expand Down
4 changes: 2 additions & 2 deletions src/pwrite.rs
Original file line number Diff line number Diff line change
@@ -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`
///
Expand Down