diff --git a/lib/entity/src/primary.rs b/lib/entity/src/primary.rs index d071373180..0902621c22 100644 --- a/lib/entity/src/primary.rs +++ b/lib/entity/src/primary.rs @@ -1,6 +1,6 @@ //! Densely numbered entity references as mapping keys. use std::marker::PhantomData; -use std::ops::{Deref, DerefMut, Index, IndexMut}; +use std::ops::{Index, IndexMut}; use std::slice; use std::vec::Vec; use {EntityRef, Iter, IterMut, Keys}; @@ -14,6 +14,11 @@ use {EntityRef, Iter, IterMut, Keys}; /// /// There should only be a single `PrimaryMap` instance for a given `EntityRef` type, otherwise /// conflicting references will be created. Using unknown keys for indexing will cause a panic. +/// +/// Note that `PrimaryMap` doesn't implement `Deref` or `DerefMut`, which would allow +/// `&PrimaryMap` to convert to `&[V]`. One of the main advantages of `PrimaryMap` is +/// that it only allows indexing with the distinct `EntityRef` key type, so converting to a +/// plain slice would make it easier to use incorrectly. #[derive(Debug, Clone)] pub struct PrimaryMap where @@ -145,26 +150,6 @@ where } } -impl Deref for PrimaryMap -where - K: EntityRef, -{ - type Target = [V]; - - fn deref(&self) -> &Self::Target { - &self.elems - } -} - -impl DerefMut for PrimaryMap -where - K: EntityRef, -{ - fn deref_mut(&mut self) -> &mut [V] { - &mut self.elems - } -} - #[cfg(test)] mod tests { use super::*; @@ -341,13 +326,4 @@ mod tests { } } } - - #[test] - fn deref() { - let mut m = PrimaryMap::::new(); - let _: &[isize] = m.as_ref(); - let _: &mut [isize] = m.as_mut(); - let _: &[isize] = &m; - let _: &mut [isize] = &mut m; - } }