0.10.3: Rust beta support
This is accomplished at a certain loss of efficiency, sadly. Add the 'nightly' feature to get things back how they were.
This commit is contained in:
parent
d04bde3509
commit
18518214c4
10
.travis.yml
10
.travis.yml
|
@ -3,11 +3,11 @@ env:
|
||||||
global:
|
global:
|
||||||
- secure: nR+DJRUQ9v03nNZMpMu1tGKLKBAqdQsTIAr8ffdl+DUEh3b2jvQ+vLLNFLPjsloqhoOXo7cWO7qVpiE4ZOq2lNDURQjdiZGFjh/Y5+xKy2BqFdV7qQ1JoBzsMyx28tQTYz0mtBsACiCYKKb+ddNX5hpwrsjp8cS7htZktA5kbiU=
|
- secure: nR+DJRUQ9v03nNZMpMu1tGKLKBAqdQsTIAr8ffdl+DUEh3b2jvQ+vLLNFLPjsloqhoOXo7cWO7qVpiE4ZOq2lNDURQjdiZGFjh/Y5+xKy2BqFdV7qQ1JoBzsMyx28tQTYz0mtBsACiCYKKb+ddNX5hpwrsjp8cS7htZktA5kbiU=
|
||||||
script:
|
script:
|
||||||
- cargo build --verbose --features clone
|
- [[ "$(rustc --version)" =~ -dev ]] && cargo test --features nightly || ! cargo test --features nightly
|
||||||
- cargo test --verbose --features clone
|
- [[ "$(rustc --version)" =~ -dev ]] && cargo test --features 'clone nightly' || ! cargo test --features 'clone nightly'
|
||||||
- cargo build --verbose
|
- cargo test --features clone
|
||||||
- cargo test --verbose
|
- cargo test
|
||||||
- cargo doc --verbose
|
- cargo doc
|
||||||
after_script:
|
after_script:
|
||||||
- ln -s target/doc doc
|
- ln -s target/doc doc
|
||||||
- curl -v http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN > ./upload-docs
|
- curl -v http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN > ./upload-docs
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "anymap"
|
name = "anymap"
|
||||||
version = "0.10.2"
|
version = "0.10.3"
|
||||||
authors = ["Chris Morgan <me@chrismorgan.info>"]
|
authors = ["Chris Morgan <me@chrismorgan.info>"]
|
||||||
description = "A safe and convenient store for one value of each type"
|
description = "A safe and convenient store for one value of each type"
|
||||||
#documentation = "http://www.rust-ci.org/chris-morgan/anymap/doc/anymap/index.html"
|
#documentation = "http://www.rust-ci.org/chris-morgan/anymap/doc/anymap/index.html"
|
||||||
|
@ -12,3 +12,4 @@ license = "MIT/Apache-2.0"
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
clone = []
|
clone = []
|
||||||
|
nightly = []
|
||||||
|
|
|
@ -20,6 +20,8 @@ Cargo all the way: it is `anymap` on crates.io.
|
||||||
|
|
||||||
There is an optional `clone` feature on the `anymap` crate; if enabled, your `AnyMap` will require contained types to implement `Clone` and will itself satisfy `Clone`.
|
There is an optional `clone` feature on the `anymap` crate; if enabled, your `AnyMap` will require contained types to implement `Clone` and will itself satisfy `Clone`.
|
||||||
|
|
||||||
|
For users of the nightly instead of the beta of rustc there are a couple of things behind the `nightly` feature like a `drain` method on the `RawAnyMap` and a more efficient hashing technique which makes lookup in the map a tad faster.
|
||||||
|
|
||||||
Author
|
Author
|
||||||
------
|
------
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
//! This crate provides the `AnyMap` type, a safe and convenient store for one value of each type.
|
//! This crate provides the `AnyMap` type, a safe and convenient store for one value of each type.
|
||||||
|
|
||||||
#![feature(core, std_misc)]
|
#![cfg_attr(feature = "nightly", feature(core, std_misc))]
|
||||||
#![cfg_attr(test, feature(test))]
|
#![cfg_attr(test, feature(test))]
|
||||||
#![warn(missing_docs, unused_results)]
|
#![warn(missing_docs, unused_results)]
|
||||||
|
|
||||||
|
|
27
src/raw.rs
27
src/raw.rs
|
@ -5,12 +5,17 @@
|
||||||
use std::any::TypeId;
|
use std::any::TypeId;
|
||||||
use std::borrow::Borrow;
|
use std::borrow::Borrow;
|
||||||
use std::collections::hash_map::{self, HashMap};
|
use std::collections::hash_map::{self, HashMap};
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
use std::collections::hash_state::HashState;
|
use std::collections::hash_state::HashState;
|
||||||
use std::default::Default;
|
use std::default::Default;
|
||||||
use std::hash::{Hash, Hasher};
|
use std::hash::Hash;
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
|
use std::hash::Hasher;
|
||||||
use std::iter::IntoIterator;
|
use std::iter::IntoIterator;
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ops::{Index, IndexMut};
|
use std::ops::{Index, IndexMut};
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
#[cfg(not(feature = "clone"))]
|
#[cfg(not(feature = "clone"))]
|
||||||
|
@ -18,13 +23,16 @@ pub use std::any::Any;
|
||||||
#[cfg(feature = "clone")]
|
#[cfg(feature = "clone")]
|
||||||
pub use with_clone::Any;
|
pub use with_clone::Any;
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
struct TypeIdHasher {
|
struct TypeIdHasher {
|
||||||
value: u64,
|
value: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg_attr(feature = "clone", derive(Clone))]
|
#[cfg_attr(feature = "clone", derive(Clone))]
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
struct TypeIdState;
|
struct TypeIdState;
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
impl HashState for TypeIdState {
|
impl HashState for TypeIdState {
|
||||||
type Hasher = TypeIdHasher;
|
type Hasher = TypeIdHasher;
|
||||||
|
|
||||||
|
@ -33,6 +41,7 @@ impl HashState for TypeIdState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
impl Hasher for TypeIdHasher {
|
impl Hasher for TypeIdHasher {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn write(&mut self, bytes: &[u8]) {
|
fn write(&mut self, bytes: &[u8]) {
|
||||||
|
@ -58,7 +67,11 @@ impl Hasher for TypeIdHasher {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
#[cfg_attr(feature = "clone", derive(Clone))]
|
#[cfg_attr(feature = "clone", derive(Clone))]
|
||||||
pub struct RawAnyMap {
|
pub struct RawAnyMap {
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
inner: HashMap<TypeId, Box<Any>, TypeIdState>,
|
inner: HashMap<TypeId, Box<Any>, TypeIdState>,
|
||||||
|
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
inner: HashMap<TypeId, Box<Any>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for RawAnyMap {
|
impl Default for RawAnyMap {
|
||||||
|
@ -67,12 +80,20 @@ impl Default for RawAnyMap {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
impl_common_methods! {
|
impl_common_methods! {
|
||||||
field: RawAnyMap.inner;
|
field: RawAnyMap.inner;
|
||||||
new() => HashMap::with_hash_state(TypeIdState);
|
new() => HashMap::with_hash_state(TypeIdState);
|
||||||
with_capacity(capacity) => HashMap::with_capacity_and_hash_state(capacity, TypeIdState);
|
with_capacity(capacity) => HashMap::with_capacity_and_hash_state(capacity, TypeIdState);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
impl_common_methods! {
|
||||||
|
field: RawAnyMap.inner;
|
||||||
|
new() => HashMap::new();
|
||||||
|
with_capacity(capacity) => HashMap::with_capacity(capacity);
|
||||||
|
}
|
||||||
|
|
||||||
/// RawAnyMap iterator.
|
/// RawAnyMap iterator.
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Iter<'a> {
|
pub struct Iter<'a> {
|
||||||
|
@ -114,14 +135,17 @@ impl ExactSizeIterator for IntoIter {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// RawAnyMap drain iterator.
|
/// RawAnyMap drain iterator.
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
pub struct Drain<'a> {
|
pub struct Drain<'a> {
|
||||||
inner: hash_map::Drain<'a, TypeId, Box<Any>>,
|
inner: hash_map::Drain<'a, TypeId, Box<Any>>,
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
impl<'a> Iterator for Drain<'a> {
|
impl<'a> Iterator for Drain<'a> {
|
||||||
type Item = Box<Any>;
|
type Item = Box<Any>;
|
||||||
#[inline] fn next(&mut self) -> Option<Box<Any>> { self.inner.next().map(|x| x.1) }
|
#[inline] fn next(&mut self) -> Option<Box<Any>> { self.inner.next().map(|x| x.1) }
|
||||||
#[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
|
#[inline] fn size_hint(&self) -> (usize, Option<usize>) { self.inner.size_hint() }
|
||||||
}
|
}
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
impl<'a> ExactSizeIterator for Drain<'a> {
|
impl<'a> ExactSizeIterator for Drain<'a> {
|
||||||
#[inline] fn len(&self) -> usize { self.inner.len() }
|
#[inline] fn len(&self) -> usize { self.inner.len() }
|
||||||
}
|
}
|
||||||
|
@ -165,6 +189,7 @@ impl RawAnyMap {
|
||||||
///
|
///
|
||||||
/// Keeps the allocated memory for reuse.
|
/// Keeps the allocated memory for reuse.
|
||||||
#[inline]
|
#[inline]
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
pub fn drain(&mut self) -> Drain {
|
pub fn drain(&mut self) -> Drain {
|
||||||
Drain {
|
Drain {
|
||||||
inner: self.inner.drain(),
|
inner: self.inner.drain(),
|
||||||
|
|
|
@ -1,7 +1,17 @@
|
||||||
use raw::Any;
|
use raw::Any;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
#[cfg(feature = "nightly")]
|
||||||
use std::raw::TraitObject;
|
use std::raw::TraitObject;
|
||||||
|
|
||||||
|
#[cfg(not(feature = "nightly"))]
|
||||||
|
#[repr(C)]
|
||||||
|
#[allow(raw_pointer_derive)]
|
||||||
|
#[derive(Copy, Clone)]
|
||||||
|
struct TraitObject {
|
||||||
|
pub data: *mut (),
|
||||||
|
pub vtable: *mut (),
|
||||||
|
}
|
||||||
|
|
||||||
#[allow(missing_docs)] // Bogus warning (it’s not public outside the crate), ☹
|
#[allow(missing_docs)] // Bogus warning (it’s not public outside the crate), ☹
|
||||||
pub trait UncheckedAnyExt {
|
pub trait UncheckedAnyExt {
|
||||||
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T;
|
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T;
|
||||||
|
|
Loading…
Reference in a new issue