Migrate import statements and macros to Rust 2018.

This commit is contained in:
Guillaume Endignoux
2020-09-23 13:47:20 +02:00
parent 55c9053baf
commit 85a34ad085
35 changed files with 81 additions and 70 deletions

View File

@@ -18,7 +18,6 @@ extern crate alloc;
#[cfg(feature = "std")]
extern crate core;
#[macro_use]
pub mod macros;
pub mod reader;
pub mod values;

View File

@@ -38,8 +38,7 @@ use core::iter::Peekable;
///
/// ```rust
/// # extern crate alloc;
/// # #[macro_use]
/// # extern crate cbor;
/// # use cbor::destructure_cbor_map;
/// #
/// # fn main() {
/// # let map = alloc::collections::BTreeMap::new();
@@ -54,8 +53,6 @@ use core::iter::Peekable;
///
/// ```rust
/// # extern crate alloc;
/// # #[macro_use]
/// # extern crate cbor;
/// #
/// # fn main() {
/// # let mut map = alloc::collections::BTreeMap::<cbor::KeyType, _>::new();
@@ -71,7 +68,7 @@ macro_rules! destructure_cbor_map {
// sorted - the behavior is unspecified if the keys are not sorted.
// Therefore, in test mode we add assertions that the keys are indeed sorted.
#[cfg(test)]
assert_sorted_keys!($( $key, )+);
$crate::assert_sorted_keys!($( $key, )+);
use $crate::values::{IntoCborKey, Value};
use $crate::macros::destructure_cbor_map_peek_value;
@@ -144,7 +141,7 @@ macro_rules! assert_sorted_keys {
k2,
);
}
assert_sorted_keys!($key2, $( $keys, )*);
$crate::assert_sorted_keys!($key2, $( $keys, )*);
};
}
@@ -227,7 +224,7 @@ macro_rules! cbor_array_vec {
}};
}
#[cfg(test)]
#[macro_export]
macro_rules! cbor_true {
( ) => {
$crate::values::Value::Simple($crate::values::SimpleValue::TrueValue)
@@ -248,7 +245,7 @@ macro_rules! cbor_null {
};
}
#[cfg(test)]
#[macro_export]
macro_rules! cbor_undefined {
( ) => {
$crate::values::Value::Simple($crate::values::SimpleValue::Undefined)
@@ -267,28 +264,28 @@ macro_rules! cbor_bool {
#[macro_export]
macro_rules! cbor_unsigned {
( $x:expr ) => {
cbor_key_unsigned!($x).into()
$crate::cbor_key_unsigned!($x).into()
};
}
#[macro_export]
macro_rules! cbor_int {
( $x:expr ) => {
cbor_key_int!($x).into()
$crate::cbor_key_int!($x).into()
};
}
#[macro_export]
macro_rules! cbor_text {
( $x:expr ) => {
cbor_key_text!($x).into()
$crate::cbor_key_text!($x).into()
};
}
#[macro_export]
macro_rules! cbor_bytes {
( $x:expr ) => {
cbor_key_bytes!($x).into()
$crate::cbor_key_bytes!($x).into()
};
}
@@ -296,7 +293,7 @@ macro_rules! cbor_bytes {
#[macro_export]
macro_rules! cbor_bytes_lit {
( $x:expr ) => {
cbor_bytes!(($x as &[u8]).to_vec())
$crate::cbor_bytes!(($x as &[u8]).to_vec())
};
}

View File

@@ -13,6 +13,7 @@
// limitations under the License.
use super::values::{Constants, KeyType, SimpleValue, Value};
use crate::{cbor_array_vec, cbor_bytes_lit, cbor_map_btree, cbor_text, cbor_unsigned};
use alloc::collections::BTreeMap;
use alloc::str;
use alloc::vec::Vec;
@@ -214,6 +215,10 @@ impl<'a> Reader<'a> {
#[cfg(test)]
mod test {
use super::*;
use crate::{
cbor_array, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null, cbor_true,
cbor_undefined,
};
#[test]
fn test_read_unsigned() {

View File

@@ -239,6 +239,8 @@ where
#[cfg(test)]
mod test {
use crate::{cbor_key_bytes, cbor_key_int, cbor_key_text};
#[test]
fn test_key_type_ordering() {
assert!(cbor_key_int!(0) < cbor_key_int!(23));

View File

@@ -92,6 +92,10 @@ impl<'a> Writer<'a> {
#[cfg(test)]
mod test {
use super::*;
use crate::{
cbor_array, cbor_array_vec, cbor_bytes, cbor_false, cbor_int, cbor_map, cbor_null,
cbor_text, cbor_true, cbor_undefined,
};
fn write_return(value: Value) -> Option<Vec<u8>> {
let mut encoded_cbor = Vec::new();