Skip to content

Commit

Permalink
Merge pull request #138 from cuviper/2018
Browse files Browse the repository at this point in the history
Upgrade to 2018 edition
  • Loading branch information
cuviper authored Jul 21, 2020
2 parents d293267 + e8c7789 commit 041ee54
Show file tree
Hide file tree
Showing 20 changed files with 172 additions and 222 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[package]
name = "indexmap"
edition = "2018"
version = "1.5.0"
authors = [
"bluss",
Expand Down
5 changes: 1 addition & 4 deletions benches/bench.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#![feature(test)]
extern crate fnv;
extern crate rand;

extern crate test;
#[macro_use]
extern crate lazy_static;
Expand All @@ -13,8 +12,6 @@ type FnvBuilder = BuildHasherDefault<FnvHasher>;
use test::black_box;
use test::Bencher;

extern crate indexmap;

use indexmap::IndexMap;

use std::collections::HashMap;
Expand Down
5 changes: 1 addition & 4 deletions benches/faststring.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
#![feature(test)]
extern crate lazy_static;
extern crate rand;

extern crate test;

use test::Bencher;

extern crate indexmap;

use indexmap::IndexMap;

use std::collections::HashMap;
Expand Down
2 changes: 0 additions & 2 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate autocfg;

fn main() {
let ac = autocfg::new();
ac.emit_sysroot_crate("std");
Expand Down
2 changes: 1 addition & 1 deletion src/equivalent.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::borrow::Borrow;
use core::borrow::Borrow;

/// Key equivalence trait.
///
Expand Down
30 changes: 11 additions & 19 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// We *mostly* avoid unsafe code, but `map::core::raw` allows it to use `RawTable` buckets.
#![deny(unsafe_code)]
#![warn(rust_2018_idioms)]
#![doc(html_root_url = "https://docs.rs/indexmap/1/")]
#![cfg_attr(not(has_std), no_std)]
#![no_std]

//! [`IndexMap`] is a hash table where the iteration order of the key-value
//! pairs is independent of the hash values of the keys.
Expand Down Expand Up @@ -33,8 +34,6 @@
//! to use alternate hashers:
//!
//! ```
//! # extern crate fnv;
//! # extern crate fxhash;
//! use fnv::FnvBuildHasher;
//! use fxhash::FxBuildHasher;
//! use indexmap::{IndexMap, IndexSet};
Expand Down Expand Up @@ -82,22 +81,15 @@
#[cfg(not(has_std))]
extern crate alloc;

extern crate hashbrown;
#[cfg(has_std)]
#[macro_use]
extern crate std;

#[cfg(not(has_std))]
pub(crate) mod std {
pub use core::*;
pub mod alloc {
pub use alloc::*;
}
pub mod collections {
pub use alloc::collections::*;
}
pub use alloc::vec;
}
use alloc::vec::{self, Vec};

#[cfg(not(has_std))]
use std::vec::Vec;
#[cfg(has_std)]
use std::vec::{self, Vec};

#[macro_use]
mod macros;
Expand All @@ -115,9 +107,9 @@ pub mod set;
#[cfg(feature = "rayon")]
mod rayon;

pub use equivalent::Equivalent;
pub use map::IndexMap;
pub use set::IndexSet;
pub use crate::equivalent::Equivalent;
pub use crate::map::IndexMap;
pub use crate::set::IndexSet;

// shared private items

Expand Down
24 changes: 10 additions & 14 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
#[cfg(has_std)]
#[macro_export(local_inner_macros)]
#[macro_export]
/// Create an `IndexMap` from a list of key-value pairs
///
/// ## Example
///
/// ```
/// #[macro_use] extern crate indexmap;
/// # fn main() {
/// use indexmap::indexmap;
///
/// let map = indexmap!{
/// "a" => 1,
Expand All @@ -18,16 +17,15 @@
///
/// // "a" is the first key
/// assert_eq!(map.keys().next(), Some(&"a"));
/// # }
/// ```
macro_rules! indexmap {
(@single $($x:tt)*) => (());
(@count $($rest:expr),*) => (<[()]>::len(&[$(indexmap!(@single $rest)),*]));
(@count $($rest:expr),*) => (<[()]>::len(&[$($crate::indexmap!(@single $rest)),*]));

($($key:expr => $value:expr,)+) => { indexmap!($($key => $value),+) };
($($key:expr => $value:expr,)+) => { $crate::indexmap!($($key => $value),+) };
($($key:expr => $value:expr),*) => {
{
let _cap = indexmap!(@count $($key),*);
let _cap = $crate::indexmap!(@count $($key),*);
let mut _map = $crate::IndexMap::with_capacity(_cap);
$(
_map.insert($key, $value);
Expand All @@ -38,14 +36,13 @@ macro_rules! indexmap {
}

#[cfg(has_std)]
#[macro_export(local_inner_macros)]
#[macro_export]
/// Create an `IndexSet` from a list of values
///
/// ## Example
///
/// ```
/// #[macro_use] extern crate indexmap;
/// # fn main() {
/// use indexmap::indexset;
///
/// let set = indexset!{
/// "a",
Expand All @@ -57,16 +54,15 @@ macro_rules! indexmap {
///
/// // "a" is the first value
/// assert_eq!(set.iter().next(), Some(&"a"));
/// # }
/// ```
macro_rules! indexset {
(@single $($x:tt)*) => (());
(@count $($rest:expr),*) => (<[()]>::len(&[$(indexset!(@single $rest)),*]));
(@count $($rest:expr),*) => (<[()]>::len(&[$($crate::indexset!(@single $rest)),*]));

($($value:expr,)+) => { indexset!($($value),+) };
($($value:expr,)+) => { $crate::indexset!($($value),+) };
($($value:expr),*) => {
{
let _cap = indexset!(@count $($value),*);
let _cap = $crate::indexset!(@count $($value),*);
let mut _set = $crate::IndexSet::with_capacity(_cap);
$(
_set.insert($value);
Expand Down
Loading

0 comments on commit 041ee54

Please sign in to comment.