This is accomplished at a certain loss of efficiency, sadly.
Add the 'nightly' feature to get things back how they were.
global:
- secure: nR+DJRUQ9v03nNZMpMu1tGKLKBAqdQsTIAr8ffdl+DUEh3b2jvQ+vLLNFLPjsloqhoOXo7cWO7qVpiE4ZOq2lNDURQjdiZGFjh/Y5+xKy2BqFdV7qQ1JoBzsMyx28tQTYz0mtBsACiCYKKb+ddNX5hpwrsjp8cS7htZktA5kbiU=
script:
global:
- secure: nR+DJRUQ9v03nNZMpMu1tGKLKBAqdQsTIAr8ffdl+DUEh3b2jvQ+vLLNFLPjsloqhoOXo7cWO7qVpiE4ZOq2lNDURQjdiZGFjh/Y5+xKy2BqFdV7qQ1JoBzsMyx28tQTYz0mtBsACiCYKKb+ddNX5hpwrsjp8cS7htZktA5kbiU=
script:
- - cargo build --verbose --features clone
- - cargo test --verbose --features clone
- - cargo build --verbose
- - cargo test --verbose
- - cargo doc --verbose
+ - [[ "$(rustc --version)" =~ -dev ]] && cargo test --features nightly || ! cargo test --features nightly
+ - [[ "$(rustc --version)" =~ -dev ]] && cargo test --features 'clone nightly' || ! cargo test --features 'clone nightly'
+ - cargo test --features clone
+ - cargo test
+ - cargo doc
after_script:
- ln -s target/doc doc
- curl -v http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN > ./upload-docs
after_script:
- ln -s target/doc doc
- curl -v http://www.rust-ci.org/artifacts/put?t=$RUSTCI_TOKEN > ./upload-docs
[package]
name = "anymap"
[package]
name = "anymap"
authors = ["Chris Morgan <me@chrismorgan.info>"]
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"
authors = ["Chris Morgan <me@chrismorgan.info>"]
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"
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.
+
//! 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))]
#![warn(missing_docs, unused_results)]
#![cfg_attr(test, feature(test))]
#![warn(missing_docs, unused_results)]
use std::any::TypeId;
use std::borrow::Borrow;
use std::collections::hash_map::{self, HashMap};
use std::any::TypeId;
use std::borrow::Borrow;
use std::collections::hash_map::{self, HashMap};
+#[cfg(feature = "nightly")]
use std::collections::hash_state::HashState;
use std::default::Default;
use std::collections::hash_state::HashState;
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::ops::{Index, IndexMut};
use std::mem;
use std::ops::{Index, IndexMut};
+#[cfg(feature = "nightly")]
use std::ptr;
#[cfg(not(feature = "clone"))]
use std::ptr;
#[cfg(not(feature = "clone"))]
#[cfg(feature = "clone")]
pub use with_clone::Any;
#[cfg(feature = "clone")]
pub use with_clone::Any;
+#[cfg(feature = "nightly")]
struct TypeIdHasher {
value: u64,
}
#[cfg_attr(feature = "clone", derive(Clone))]
struct TypeIdHasher {
value: u64,
}
#[cfg_attr(feature = "clone", derive(Clone))]
+#[cfg(feature = "nightly")]
+#[cfg(feature = "nightly")]
impl HashState for TypeIdState {
type Hasher = TypeIdHasher;
impl HashState for TypeIdState {
type Hasher = TypeIdHasher;
+#[cfg(feature = "nightly")]
impl Hasher for TypeIdHasher {
#[inline(always)]
fn write(&mut self, bytes: &[u8]) {
impl Hasher for TypeIdHasher {
#[inline(always)]
fn write(&mut self, bytes: &[u8]) {
#[derive(Debug)]
#[cfg_attr(feature = "clone", derive(Clone))]
pub struct RawAnyMap {
#[derive(Debug)]
#[cfg_attr(feature = "clone", derive(Clone))]
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 {
+#[cfg(feature = "nightly")]
impl_common_methods! {
field: RawAnyMap.inner;
new() => HashMap::with_hash_state(TypeIdState);
with_capacity(capacity) => HashMap::with_capacity_and_hash_state(capacity, TypeIdState);
}
impl_common_methods! {
field: RawAnyMap.inner;
new() => HashMap::with_hash_state(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.
#[derive(Clone)]
pub struct Iter<'a> {
/// RawAnyMap iterator.
#[derive(Clone)]
pub struct Iter<'a> {
}
/// RawAnyMap drain iterator.
}
/// RawAnyMap drain iterator.
+#[cfg(feature = "nightly")]
pub struct Drain<'a> {
inner: hash_map::Drain<'a, TypeId, Box<Any>>,
}
pub struct Drain<'a> {
inner: hash_map::Drain<'a, TypeId, Box<Any>>,
}
+#[cfg(feature = "nightly")]
impl<'a> Iterator for Drain<'a> {
type Item = Box<Any>;
#[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() }
}
impl<'a> Iterator for Drain<'a> {
type Item = Box<Any>;
#[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() }
}
+#[cfg(feature = "nightly")]
impl<'a> ExactSizeIterator for Drain<'a> {
#[inline] fn len(&self) -> usize { self.inner.len() }
}
impl<'a> ExactSizeIterator for Drain<'a> {
#[inline] fn len(&self) -> usize { self.inner.len() }
}
///
/// Keeps the allocated memory for reuse.
#[inline]
///
/// Keeps the allocated memory for reuse.
#[inline]
+ #[cfg(feature = "nightly")]
pub fn drain(&mut self) -> Drain {
Drain {
inner: self.inner.drain(),
pub fn drain(&mut self) -> Drain {
Drain {
inner: self.inner.drain(),
use raw::Any;
use std::mem;
use raw::Any;
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), ☹
pub trait UncheckedAnyExt {
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T;
#[allow(missing_docs)] // Bogus warning (it’s not public outside the crate), ☹
pub trait UncheckedAnyExt {
unsafe fn downcast_ref_unchecked<T: 'static>(&self) -> &T;