Skip to content

Commit 94e54c1

Browse files
committed
Upgrade syntax to Rust 2018.
1 parent d00bc9c commit 94e54c1

24 files changed

+66
-132
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ keywords = ["argdata", "cloudabi"]
66
authors = ["Mara Bos <[email protected]>"]
77
license = "BSD-2-Clause"
88
repository = "https://github.com/NuxiNL/argdata-rust"
9+
edition = "2018"
910

1011
[dependencies]
1112
byteorder = { version = "1.2.3", features = ["i128"] }

src/debug.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
use crate::{Argdata, ArgdataRef, ReadError, Value};
12
use std::fmt;
23
use std::ops::Deref;
3-
use Argdata;
4-
use ArgdataRef;
5-
use ReadError;
6-
use Value;
74

85
struct FmtError<T>(Result<T, ReadError>);
96

@@ -56,7 +53,7 @@ impl<'a, 'd> fmt::Debug for Value<'a, 'd> {
5653

5754
#[test]
5855
fn debug_fmt() {
59-
let argdata = ::encoded(
56+
let argdata = crate::encoded(
6057
&b"\x06\x87\x08Hello\x00\x87\x08World\x00\x81\x02\x82\x02\x01\x86\x09\
6158
\x70\xF1\x80\x29\x15\x84\x05\x58\xe5\xd9\x80\x83\x06\x80\x80"[..],
6259
);
@@ -66,7 +63,7 @@ fn debug_fmt() {
6663
"{\"Hello\": \"World\", false: true, timestamp(485, 88045333): 5826009, null: {null: null}}"
6764
);
6865

69-
let argdata = ::encoded(&b"\x07\x81\x02\x82\x02\x01\x80\x87\x08Hello\x00\x81\x06\x81\x07"[..]);
66+
let argdata = crate::encoded(&b"\x07\x81\x02\x82\x02\x01\x80\x87\x08Hello\x00\x81\x06\x81\x07"[..]);
7067

7168
assert_eq!(
7269
format!("{:?}", &argdata as &Argdata),

src/env.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use fd;
2-
3-
use encoded_with_fds;
4-
use values::EncodedArgdata;
1+
use crate::{encoded_with_fds, fd, values::EncodedArgdata};
52

63
/// Returns the argdata which this program was started with.
74
///

src/errors.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std;
21
use std::error::Error;
32
use std::fmt::Display;
43
use std::str::Utf8Error;

src/intvalue.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::cmp::Ordering;
33
use std::fmt;
44
use std::io;
55

6-
use super::TryFrom;
6+
use crate::TryFrom;
77

88
/// Represents a signed integer value of any size.
99
///

src/lib.rs

+11-13
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
//! Deserialization is mostly stable and tested, but the serialization
66
//! interface is probably going to change, and might have bugs.
77
8-
extern crate byteorder;
9-
108
use std::io;
119

1210
/// Access to the program environment.
@@ -25,7 +23,7 @@ use std::convert::TryFrom;
2523
mod try_from;
2624

2725
#[cfg(not(nightly))]
28-
use try_from::TryFrom;
26+
use crate::try_from::TryFrom;
2927

3028
mod debug;
3129
mod errors;
@@ -38,27 +36,27 @@ mod subfield;
3836
mod timespec;
3937
mod value;
4038

41-
pub use errors::{NoFit, NotRead, ReadError};
42-
pub use intvalue::IntValue;
43-
pub use mapiterator::{MapIterable, MapIterator};
44-
pub use reference::ArgdataRef;
45-
pub use seqiterator::{SeqIterable, SeqIterator};
46-
pub use strvalue::StrValue;
47-
pub use timespec::Timespec;
48-
pub use value::{Type, Value};
39+
pub use crate::errors::{NoFit, NotRead, ReadError};
40+
pub use crate::intvalue::IntValue;
41+
pub use crate::mapiterator::{MapIterable, MapIterator};
42+
pub use crate::reference::ArgdataRef;
43+
pub use crate::seqiterator::{SeqIterable, SeqIterator};
44+
pub use crate::strvalue::StrValue;
45+
pub use crate::timespec::Timespec;
46+
pub use crate::value::{Type, Value};
4947

5048
#[path = "values/mod.rs"]
5149
mod values_;
5250

53-
pub use values_::{
51+
pub use crate::values_::{
5452
bigint, binary, bool, encoded, encoded_fd, encoded_with_fds, float, int, invalid_fd, map, null,
5553
process_fd, seq, str, timestamp,
5654
};
5755

5856
/// Implementations of specific `Argdata` types.
5957
/// Use the functions in the root of this crate to create them.
6058
pub mod values {
61-
pub use values_::{
59+
pub use crate::values_::{
6260
BigInt, Binary, Bool, EncodedArgdata, Float, Int, Map, Null, Seq, Str, Timestamp,
6361
};
6462
}

src/mapiterator.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use ArgdataRef;
2-
use ReadError;
1+
use crate::{ArgdataRef, ReadError};
32

43
/// An iterator, iterating over an argdata map.
54
#[derive(Copy, Clone)]
@@ -12,9 +11,9 @@ pub struct MapIterator<'a, 'd: 'a> {
1211
pub trait MapIterable<'d>: Sync {
1312
/// Iterate to the next key-value pair, returning None if the end is reached.
1413
///
15-
/// **Don't use this method directly.**
16-
/// Instead, get a [`MapIterator`] (using [`::Argdata::read_map`]), and
17-
/// use it as any other [`Iterator`].
14+
/// **Don't use this method directly.** Instead, get a [`MapIterator`]
15+
/// (using [`Argdata::read_map`](crate::Argdata::read_map)), and use it as
16+
/// any other [`Iterator`].
1817
///
1918
/// # For implementors
2019
///
@@ -23,8 +22,8 @@ pub trait MapIterable<'d>: Sync {
2322
/// the `cookie` is implementation-specific. It might for example be the
2423
/// index into a vector, or the byte-offset into an encoded argdata value.
2524
/// The initial value is also implementation specific, so provide a method
26-
/// (such as [`::Argdata::read_map`]) which provides users with a properly
27-
/// initialized [`MapIterator`].
25+
/// (such as [`Argdata::read_map`](crate::Argdata::read_map)) which
26+
/// provides users with a properly initialized [`MapIterator`].
2827
///
2928
/// # Panics
3029
///
@@ -42,7 +41,8 @@ impl<'a, 'd: 'a> MapIterator<'a, 'd> {
4241
///
4342
/// This should only be used in implementations of [`MapIterable`].
4443
///
45-
/// To get a map iterator over Argdata use [`::Argdata::read_map`].
44+
/// To get a map iterator over Argdata use
45+
/// [`Argdata::read_map`](crate::Argdata::read_map).
4646
pub fn new(map: &'a (MapIterable<'d> + 'a), cookie: usize) -> Self {
4747
MapIterator { map, cookie }
4848
}

src/reference.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
use fd;
1+
use crate::{fd, values, Argdata};
22
use std::ops::Deref;
3-
use values;
4-
use Argdata;
53

64
/// A reference to an argdata value.
75
/// Either a substring of an encoded argdata value, or just a `&Argdata`.
@@ -13,7 +11,7 @@ impl<'a, 'd: 'a> ArgdataRef<'a, 'd> {
1311
/// Create an ArgdataRef that refers to a substring of an encoded argdata value.
1412
pub fn encoded(bytes: &'d [u8], convert_fd: &'a (fd::ConvertFd + 'a)) -> ArgdataRef<'a, 'd> {
1513
ArgdataRef {
16-
inner: Inner::Encoded(::encoded_with_fds(bytes, convert_fd)),
14+
inner: Inner::Encoded(crate::encoded_with_fds(bytes, convert_fd)),
1715
}
1816
}
1917

src/seqiterator.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use ArgdataRef;
2-
use ReadError;
1+
use crate::{ArgdataRef, ReadError};
32

43
/// An iterator, iterating over an argdata sequence.
54
#[derive(Copy, Clone)]
@@ -12,9 +11,9 @@ pub struct SeqIterator<'a, 'd: 'a> {
1211
pub trait SeqIterable<'d>: Sync {
1312
/// Iterate to the next element, returning None if the end is reached.
1413
///
15-
/// **Don't use this method directly.**
16-
/// Instead, get a [`SeqIterator`] (using [`::Argdata::read_seq`]), and
17-
/// use it as any other [`Iterator`].
14+
/// **Don't use this method directly.** Instead, get a [`SeqIterator`]
15+
/// (using [`Argdata::read_seq`](crate::Argdata::read_seq)), and use it as
16+
/// any other [`Iterator`].
1817
///
1918
/// # For implementors
2019
///
@@ -23,8 +22,8 @@ pub trait SeqIterable<'d>: Sync {
2322
/// the `cookie` is implementation-specific. It might for example be the
2423
/// index into a vector, or the byte-offset into an encoded argdata value.
2524
/// The initial value is also implementation specific, so provide a method
26-
/// (such as [`::Argdata::read_seq`]) which provides users with a properly
27-
/// initialized [`SeqIterator`].
25+
/// (such as [`Argdata::read_seq`](crate::Argdata::read_seq)) which
26+
/// provides users with a properly initialized [`SeqIterator`].
2827
///
2928
/// # Panics
3029
///
@@ -42,7 +41,8 @@ impl<'a, 'd: 'a> SeqIterator<'a, 'd> {
4241
///
4342
/// This should only be used in implementations of [`SeqIterable`].
4443
///
45-
/// To get a seq iterator over Argdata use [`::Argdata::read_seq`].
44+
/// To get a seq iterator over Argdata use
45+
/// [`Argdata::read_seq`](crate::Argdata::read_seq).
4646
pub fn new(seq: &'a (SeqIterable<'d> + 'a), cookie: usize) -> Self {
4747
SeqIterator { seq, cookie }
4848
}

src/strvalue.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use std;
21
use std::ffi::{CStr, FromBytesWithNulError};
32
use std::str::Utf8Error;
43

src/subfield.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1+
use crate::ReadError;
12
use std::io;
23

3-
use ReadError;
4-
54
pub fn read_subfield(data: &[u8]) -> (Option<Result<&[u8], ReadError>>, usize) {
65
if data.is_empty() {
76
return (None, 0);

src/value.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
use fd;
2-
use IntValue;
3-
use MapIterator;
4-
use SeqIterator;
5-
use StrValue;
6-
use Timespec;
1+
use crate::{fd, IntValue, MapIterator, SeqIterator, StrValue, Timespec};
72

83
/// The type of an argdata value.
94
#[derive(Debug, PartialEq, Eq, Hash)]

src/values/bigint.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
use fd;
1+
use crate::{fd, Argdata, IntValue, ReadError, Value};
22
use std::io;
3-
use Argdata;
4-
use IntValue;
5-
use ReadError;
6-
use Value;
73

84
/// A big-endian 2's-complement signed arbitrary length integer.
95
#[derive(Clone, Copy, Debug)]

src/values/binary.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use fd;
1+
use crate::{fd, Argdata, ReadError, Value};
22
use std::io;
3-
use Argdata;
4-
use ReadError;
5-
use Value;
63

74
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
85
pub struct Binary<'d> {

src/values/bool.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use fd;
1+
use crate::{fd, Argdata, ReadError, Value};
22
use std::io;
3-
use Argdata;
4-
use ReadError;
5-
use Value;
63

74
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
85
pub struct Bool {

src/values/encoded.rs

+8-20
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1+
use crate::{
2+
fd, fd::EncodedFd, subfield::read_subfield, Argdata, ArgdataRef, IntValue, MapIterable,
3+
MapIterator, NoFit, NotRead, ReadError, SeqIterable, SeqIterator, StrValue, Timespec, Type,
4+
};
15
use byteorder::{BigEndian, ByteOrder};
2-
use fd;
3-
use fd::EncodedFd;
46
use std::io;
5-
use subfield::read_subfield;
6-
use Argdata;
7-
use ArgdataRef;
8-
use IntValue;
9-
use MapIterable;
10-
use MapIterator;
11-
use NoFit;
12-
use NotRead;
13-
use ReadError;
14-
use SeqIterable;
15-
use SeqIterator;
16-
use StrValue;
17-
use Timespec;
18-
use Type;
197

208
#[derive(Clone, Copy, Debug)]
219
pub struct EncodedArgdata<'d, F> {
@@ -345,7 +333,7 @@ fn read_float_test() {
345333

346334
#[test]
347335
fn read_int_test() {
348-
use ArgdataExt;
336+
use crate::ArgdataExt;
349337
assert_eq!(encoded(b"\x05").read_int(), Ok(0));
350338
assert_eq!(encoded(b"\x05\x01").read_int(), Ok(1));
351339
assert_eq!(encoded(b"\x05\xFF").read_int(), Ok(-1));
@@ -358,7 +346,7 @@ fn read_int_test() {
358346

359347
#[test]
360348
fn read_map_test() {
361-
use ArgdataExt;
349+
use crate::ArgdataExt;
362350
assert_eq!(encoded(b"\x06").read_map().unwrap().count(), 0);
363351
assert_eq!(encoded(b"\x07").read_map().unwrap_err(), NoFit::DifferentType.into());
364352
assert_eq!(encoded(b"\x04").read_map().unwrap_err(), NoFit::DifferentType.into());
@@ -386,7 +374,7 @@ fn read_map_test() {
386374

387375
#[test]
388376
fn read_seq_test() {
389-
use ArgdataExt;
377+
use crate::ArgdataExt;
390378
assert_eq!(encoded(b"\x07").read_seq().unwrap().count(), 0);
391379
assert_eq!(encoded(b"\x06").read_seq().unwrap_err(), NoFit::DifferentType.into());
392380
assert_eq!(encoded(b"\x04").read_seq().unwrap_err(), NoFit::DifferentType.into());
@@ -415,7 +403,7 @@ fn read_seq_test() {
415403

416404
#[test]
417405
fn read_str_test() {
418-
use ArgdataExt;
406+
use crate::ArgdataExt;
419407
assert_eq!(encoded(b"\x08\x00").read_str(), Ok(""));
420408
assert_eq!(encoded(b"\x08Hello World!\x00").read_str(), Ok("Hello World!"));
421409
assert_eq!(encoded(b"\x08\xCE\xB1\xCE\xB2\xCE\xBE\xCE\xB4\x00").read_str(), Ok("αβξδ"));

src/values/fd.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1+
use crate::{fd, Argdata, ReadError, Value};
12
use byteorder::{BigEndian, ByteOrder};
2-
use fd;
33
use std::io;
44
use std::os::raw::c_int;
5-
use Argdata;
6-
use ReadError;
7-
use Value;
85

96
/// Create an argdata value representing a file descriptor of this process.
107
pub fn process_fd(fd: c_int) -> fd::Fd {

src/values/float.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
1+
use crate::{fd, Argdata, ReadError, Value};
12
use byteorder::{BigEndian, ByteOrder};
2-
use fd;
33
use std::io;
4-
use Argdata;
5-
use ReadError;
6-
use Value;
74

85
#[derive(Clone, Copy, PartialEq, PartialOrd, Debug)]
96
pub struct Float {

src/values/int.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
1-
use fd;
1+
use crate::{fd, Argdata, IntValue, ReadError, Value};
22
use std::io;
3-
use Argdata;
4-
use IntValue;
5-
use ReadError;
6-
use Value;
73

84
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
95
pub struct Int<T> {

src/values/map.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
use container_traits::MapContainer;
2-
use fd;
1+
use crate::{
2+
container_traits::MapContainer,
3+
fd,
4+
subfield::{subfield_length, write_subfield_length},
5+
Argdata, ArgdataRef, MapIterable, MapIterator, ReadError, Value,
6+
};
37
use std::io;
4-
use subfield::{subfield_length, write_subfield_length};
5-
use Argdata;
6-
use ArgdataRef;
7-
use MapIterable;
8-
use MapIterator;
9-
use ReadError;
10-
use Value;
118

129
#[derive(Clone, Copy, Debug)]
1310
pub struct Map<'d, T: 'd> {

src/values/null.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
1-
use fd;
1+
use crate::{fd, Argdata, ReadError, Value};
22
use std::io;
3-
use Argdata;
4-
use ReadError;
5-
use Value;
63

74
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
85
pub struct Null;

0 commit comments

Comments
 (0)