Skip to content

Commit 0289dd4

Browse files
authored
Edition 2018 (#8)
* Update to Edition 2018 * Remove CopyCell::get_mut
1 parent 64dab6d commit 0289dd4

File tree

12 files changed

+111
-235
lines changed

12 files changed

+111
-235
lines changed

Cargo.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
[package]
22
name = "toolshed"
3-
version = "0.7.0"
3+
version = "0.8.0"
44
authors = ["maciejhirsz <[email protected]>"]
55
license = "MIT/Apache-2.0"
66
description = "Arena allocator and a handful of useful data structures"
77
repository = "https://github.com/ratel-rust/toolshed"
88
documentation = "https://docs.rs/toolshed/"
99
readme = "README.md"
10+
edition = "2018"
1011

1112
[dependencies]
12-
fxhash = "0.2"
13+
rustc-hash = "1.0"
1314
serde = { version = "1.0", optional = true }
1415

1516
[dev-dependencies]

benches/bloomset.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
#![feature(test)]
22
extern crate test;
3-
extern crate fxhash;
4-
extern crate toolshed;
53

64
use toolshed::set::{BloomSet, Set};
75
use toolshed::Arena;
86
use test::{Bencher, black_box};
97
use std::collections::HashSet;
10-
use fxhash::FxHashSet;
8+
use rustc_hash::FxHashSet;
119

1210
static WORDS: &[&str] = &[
1311
"ARENA_BLOCK", "Arena", "Cell", "Self", "String", "T", "Vec", "_unchecked", "a",

benches/list.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#![feature(test)]
22
extern crate test;
3-
extern crate fxhash;
4-
extern crate toolshed;
53

64
use toolshed::list::ListBuilder;
75
use toolshed::Arena;

src/arena.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub struct Arena {
2323
}
2424

2525
/// A pointer to an uninitialized region of memory.
26-
pub struct Uninitialized<'arena, T: Copy + 'arena> {
26+
pub struct Uninitialized<'arena, T: Copy> {
2727
pointer: &'arena mut MaybeUninit<T>,
2828
}
2929

@@ -33,7 +33,7 @@ union MaybeUninit<T: Copy> {
3333
_uninit: (),
3434
}
3535

36-
impl<'arena, T: Copy + 'arena> Uninitialized<'arena, T> {
36+
impl<'arena, T: Copy> Uninitialized<'arena, T> {
3737
/// Initialize the memory at the pointer with a given value.
3838
#[inline]
3939
pub fn init(self, value: T) -> &'arena mut T {
@@ -69,7 +69,7 @@ impl<'arena, T: Copy + 'arena> Uninitialized<'arena, T> {
6969
}
7070
}
7171

72-
impl<'arena, T: Copy + 'arena> From<&'arena mut T> for Uninitialized<'arena, T> {
72+
impl<'arena, T: Copy> From<&'arena mut T> for Uninitialized<'arena, T> {
7373
#[inline]
7474
fn from(pointer: &'arena mut T) -> Self {
7575
unsafe { Self::from_raw(pointer) }
@@ -102,7 +102,6 @@ impl<'arena> NulTermStr<'arena> {
102102
/// would otherwise have to be length checks.
103103
///
104104
/// ```rust
105-
/// # extern crate toolshed;
106105
/// # use toolshed::Arena;
107106
/// # fn main() {
108107
/// let arena = Arena::new();
@@ -452,11 +451,9 @@ mod test {
452451
assert_eq!(arena.offset.get(), 16);
453452
assert_eq!(
454453
allocated,
455-
&[
456-
b'a', b'b', b'c', b'd', b'e', b'f', b'g', b'h', b'i', b'j', b'k', 0
457-
]
454+
"abcdefghijk\u{0}".as_bytes(),
458455
);
459456

460-
assert_eq!(nts.to_string(), "abcdefghijk");
457+
assert_eq!(&**nts, "abcdefghijk");
461458
}
462459
}

src/cell.rs

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::marker::PhantomData;
66
/// This should be identical to the `Cell` implementation in the standard
77
/// library, but always require that the internal type implements `Copy`
88
/// and implements `Copy` itself.
9-
#[derive(PartialEq, Eq)]
9+
#[derive(PartialEq, Eq, Copy, Clone)]
1010
#[repr(transparent)]
1111
pub struct CopyCell<T> {
1212
/// Internal value
@@ -23,8 +23,7 @@ unsafe impl<T> Send for CopyCell<T> {}
2323

2424
impl<T> CopyCell<T> {
2525
/// Creates a new `CopyCell` containing the given value.
26-
#[inline]
27-
pub fn new(value: T) -> Self {
26+
pub const fn new(value: T) -> Self {
2827
CopyCell {
2928
value,
3029
_no_sync: PhantomData
@@ -39,19 +38,6 @@ impl<T: Copy> CopyCell<T> {
3938
self.value
4039
}
4140

42-
/// Returns a mutable reference to the underlying data.
43-
///
44-
/// This call borrows `CopyCell` mutably, which gives us a compile time
45-
/// memory safety guarantee.
46-
#[inline]
47-
pub fn get_mut<'a>(&'a mut self) -> &'a mut T {
48-
// We can just cast the pointer from `CopyCell<T>` to `T` because of
49-
// #[repr(transparent)]
50-
unsafe {
51-
&mut *(self as *mut CopyCell<T> as *mut T)
52-
}
53-
}
54-
5541
/// Sets the contained value.
5642
#[inline]
5743
pub fn set(&self, value: T) {
@@ -71,19 +57,10 @@ impl<T: Copy> CopyCell<T> {
7157
}
7258
}
7359

74-
impl<T: Copy> Clone for CopyCell<T> {
75-
#[inline]
76-
fn clone(&self) -> CopyCell<T> {
77-
CopyCell::new(self.get())
78-
}
79-
}
80-
81-
impl<T: Copy> Copy for CopyCell<T> { }
82-
83-
impl<T: Debug + Copy> Debug for CopyCell<T> {
60+
impl<T: Debug> Debug for CopyCell<T> {
8461
#[inline]
8562
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
86-
Debug::fmt(&self.get(), f)
63+
Debug::fmt(&self.value, f)
8764
}
8865
}
8966

@@ -94,8 +71,8 @@ mod test {
9471
#[test]
9572
fn cell() {
9673
let cell_a = CopyCell::new(42u64);
97-
let mut cell_b = cell_a; // copy
98-
let cell_c = &cell_a; // reference
74+
let cell_b = cell_a; // copy
75+
let cell_c = &cell_a; // reference
9976

10077
assert_eq!(cell_a.get(), 42);
10178
assert_eq!(cell_b.get(), 42);
@@ -116,7 +93,7 @@ mod test {
11693
assert_eq!(cell_c.get(), 200);
11794

11895
// Again, only affects the copy
119-
*cell_b.get_mut() = 300;
96+
cell_b.set(300);
12097

12198
assert_eq!(cell_a.get(), 200);
12299
assert_eq!(cell_b.get(), 300);

src/impl_debug.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{self, Debug};
2-
use list::{List, GrowableList, ListBuilder};
3-
use map::{Map, BloomMap};
4-
use set::{Set, BloomSet};
2+
use crate::list::{List, GrowableList, ListBuilder};
3+
use crate::map::{Map, BloomMap};
4+
use crate::set::{Set, BloomSet};
55

66
impl<'arena, T> Debug for List<'arena, T>
77
where
@@ -78,7 +78,7 @@ where
7878
#[cfg(test)]
7979
mod test {
8080
use super::*;
81-
use Arena;
81+
use crate::Arena;
8282

8383
#[test]
8484
fn list_debug() {

src/impl_partial_eq.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use list::List;
2-
use map::{Map, BloomMap};
3-
use set::{Set, BloomSet};
1+
use crate::list::List;
2+
use crate::map::{Map, BloomMap};
3+
use crate::set::{Set, BloomSet};
44

55
impl<'a, 'b, A, B> PartialEq<List<'b, B>> for List<'a, A>
66
where

src/impl_serialize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use serde::ser::{Serialize, Serializer};
2-
use list::List;
3-
use map::{Map, BloomMap};
4-
use set::{Set, BloomSet};
2+
use crate::list::List;
3+
use crate::map::{Map, BloomMap};
4+
use crate::set::{Set, BloomSet};
55

66
impl<'arena, T> Serialize for List<'arena, T>
77
where
@@ -74,7 +74,7 @@ where
7474
mod test {
7575
use super::*;
7676
use serde_json;
77-
use Arena;
77+
use crate::Arena;
7878

7979
#[test]
8080
fn list_can_be_serialized() {

src/lib.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,6 @@
3232
//! ## Example
3333
//!
3434
//! ```rust
35-
//!
36-
//! extern crate toolshed;
37-
//!
3835
//! use toolshed::Arena;
3936
//! use toolshed::map::Map;
4037
//!
@@ -92,13 +89,11 @@
9289

9390
// Pull in serde if `impl_serialize` is enabled
9491
#[cfg(feature = "impl_serialize")]
95-
extern crate serde;
92+
use serde;
9693

9794
// Pull in serde_json for testing if `impl_serialize` is enabled
9895
#[cfg(all(test, feature = "impl_serialize"))]
99-
extern crate serde_json;
100-
101-
extern crate fxhash;
96+
use serde_json;
10297

10398
mod cell;
10499
pub mod map;
@@ -112,5 +107,5 @@ mod impl_debug;
112107
#[cfg(feature = "impl_serialize")]
113108
mod impl_serialize;
114109

115-
pub use arena::{Arena, Uninitialized, NulTermStr};
116-
pub use cell::CopyCell;
110+
pub use self::arena::{Arena, Uninitialized, NulTermStr};
111+
pub use self::cell::CopyCell;

0 commit comments

Comments
 (0)