0.9.11: Rust update
This commit is contained in:
parent
8e12affa59
commit
b84ee0b14e
2 changed files with 15 additions and 11 deletions
|
@ -1,6 +1,6 @@
|
|||
[package]
|
||||
name = "anymap"
|
||||
version = "0.9.10"
|
||||
version = "0.9.11"
|
||||
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"
|
||||
|
|
24
src/lib.rs
24
src/lib.rs
|
@ -13,10 +13,11 @@ use std::any::{Any, TypeId};
|
|||
use std::mem::forget;
|
||||
use std::collections::HashMap;
|
||||
use std::collections::hash_map;
|
||||
use std::hash::{Hasher, Writer};
|
||||
use std::hash::Hasher;
|
||||
use std::collections::hash_state::HashState;
|
||||
use std::mem::transmute;
|
||||
use std::raw::TraitObject;
|
||||
use std::marker::PhantomData;
|
||||
|
||||
struct TypeIdHasher {
|
||||
value: u64,
|
||||
|
@ -32,7 +33,7 @@ impl HashState for TypeIdState {
|
|||
}
|
||||
}
|
||||
|
||||
impl Writer for TypeIdHasher {
|
||||
impl Hasher for TypeIdHasher {
|
||||
#[inline(always)]
|
||||
fn write(&mut self, bytes: &[u8]) {
|
||||
// This expects to receive one and exactly one 64-bit value
|
||||
|
@ -43,13 +44,8 @@ impl Writer for TypeIdHasher {
|
|||
1)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Hasher for TypeIdHasher {
|
||||
type Output = u64;
|
||||
|
||||
fn reset(&mut self) { }
|
||||
|
||||
#[inline(always)]
|
||||
fn finish(&self) -> u64 { self.value }
|
||||
}
|
||||
|
||||
|
@ -268,8 +264,14 @@ impl AnyMap {
|
|||
#[stable]
|
||||
pub fn entry<T: Any + 'static>(&mut self) -> Entry<T> {
|
||||
match self.data.entry(TypeId::of::<T>()) {
|
||||
hash_map::Entry::Occupied(e) => Entry::Occupied(OccupiedEntry { entry: e }),
|
||||
hash_map::Entry::Vacant(e) => Entry::Vacant(VacantEntry { entry: e }),
|
||||
hash_map::Entry::Occupied(e) => Entry::Occupied(OccupiedEntry {
|
||||
entry: e,
|
||||
type_: PhantomData,
|
||||
}),
|
||||
hash_map::Entry::Vacant(e) => Entry::Vacant(VacantEntry {
|
||||
entry: e,
|
||||
type_: PhantomData,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -312,12 +314,14 @@ impl AnyMap {
|
|||
#[stable]
|
||||
pub struct OccupiedEntry<'a, V: 'a> {
|
||||
entry: hash_map::OccupiedEntry<'a, TypeId, Box<Any + 'static>>,
|
||||
type_: PhantomData<V>,
|
||||
}
|
||||
|
||||
/// A view into a single empty location in an AnyMap
|
||||
#[stable]
|
||||
pub struct VacantEntry<'a, V: 'a> {
|
||||
entry: hash_map::VacantEntry<'a, TypeId, Box<Any + 'static>>,
|
||||
type_: PhantomData<V>,
|
||||
}
|
||||
|
||||
/// A view into a single location in an AnyMap, which may be vacant or occupied
|
||||
|
|
Loading…
Add table
Reference in a new issue