From b84ee0b14e3140eb7325686d4a22732d0bd7399b Mon Sep 17 00:00:00 2001 From: Chris Morgan Date: Tue, 24 Feb 2015 11:59:02 +1100 Subject: [PATCH] 0.9.11: Rust update --- Cargo.toml | 2 +- src/lib.rs | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 6b34ed7..606aace 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "anymap" -version = "0.9.10" +version = "0.9.11" authors = ["Chris Morgan "] 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" diff --git a/src/lib.rs b/src/lib.rs index c4c2161..135fa0a 100644 --- a/src/lib.rs +++ b/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(&mut self) -> Entry { match self.data.entry(TypeId::of::()) { - 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>, + type_: PhantomData, } /// A view into a single empty location in an AnyMap #[stable] pub struct VacantEntry<'a, V: 'a> { entry: hash_map::VacantEntry<'a, TypeId, Box>, + type_: PhantomData, } /// A view into a single location in an AnyMap, which may be vacant or occupied -- 2.42.0