X-Git-Url: https://git.chrismorgan.info/anymap/blobdiff_plain/cefa48967d5fcd88343b90a4cb32c59b44b3272a..de091453093fb5139de71b085411d2fad1a52275:/src/lib.rs diff --git a/src/lib.rs b/src/lib.rs index e118a43..24c4620 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,6 @@ //! This crate provides the `AnyMap` type, a safe and convenient store for one value of each type. -#![crate_name = "anymap"] -#![crate_type = "lib"] -#![feature(default_type_params, tuple_indexing)] +#![feature(default_type_params)] #![warn(unused_qualifications, non_upper_case_globals, variant_size_differences, unused_typecasts, missing_docs, unused_results)] @@ -15,7 +13,7 @@ use std::intrinsics::{forget, TypeId}; use std::collections::HashMap; use std::collections::hash_map; use std::hash::{Hash, Hasher, Writer}; -use std::mem::{transmute, transmute_copy}; +use std::mem::transmute; use std::raw::TraitObject; pub use Entry::{Vacant, Occupied}; @@ -56,11 +54,11 @@ trait UncheckedAnyRefExt<'a> { unsafe fn downcast_ref_unchecked(self) -> &'a T; } -impl<'a> UncheckedAnyRefExt<'a> for &'a Any + 'a { +impl<'a> UncheckedAnyRefExt<'a> for &'a Any { #[inline] unsafe fn downcast_ref_unchecked(self) -> &'a T { // Get the raw representation of the trait object - let to: TraitObject = transmute_copy(&self); + let to: TraitObject = transmute(self); // Extract the data pointer transmute(to.data) @@ -74,11 +72,11 @@ trait UncheckedAnyMutRefExt<'a> { unsafe fn downcast_mut_unchecked(self) -> &'a mut T; } -impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any + 'a { +impl<'a> UncheckedAnyMutRefExt<'a> for &'a mut Any { #[inline] unsafe fn downcast_mut_unchecked(self) -> &'a mut T { // Get the raw representation of the trait object - let to: TraitObject = transmute_copy(&self); + let to: TraitObject = transmute(self); // Extract the data pointer transmute(to.data) @@ -190,8 +188,8 @@ impl AnyMap { /// Gets the given key's corresponding entry in the map for in-place manipulation pub fn entry(&mut self) -> Entry { match self.data.entry(TypeId::of::()) { - hash_map::Occupied(e) => Occupied(OccupiedEntry { entry: e }), - hash_map::Vacant(e) => Vacant(VacantEntry { entry: e }), + hash_map::Entry::Occupied(e) => Occupied(OccupiedEntry { entry: e }), + hash_map::Entry::Vacant(e) => Vacant(VacantEntry { entry: e }), } } @@ -211,12 +209,12 @@ impl AnyMap { } } -/// A view into a single occupied location in a HashMap +/// A view into a single occupied location in an AnyMap pub struct OccupiedEntry<'a, V: 'a> { entry: hash_map::OccupiedEntry<'a, TypeId, Box>, } -/// A view into a single empty location in a HashMap +/// A view into a single empty location in an AnyMap pub struct VacantEntry<'a, V: 'a> { entry: hash_map::VacantEntry<'a, TypeId, Box>, }