diff --git a/src/vec32.rs b/src/vec32.rs index 155208b..12b7a9e 100644 --- a/src/vec32.rs +++ b/src/vec32.rs @@ -8,7 +8,7 @@ // copied, modified, or distributed except according to those terms. -use std::{cmp, fmt, iter, mem, ops, ptr, slice, u32, vec}; +use std::{borrow, cmp, fmt, iter, mem, ops, ptr, slice, u32, vec}; use std::ptr::NonNull; /// A vector that is indexed by `u32` instead of `usize`. @@ -310,6 +310,48 @@ macro_rules! vec32 { // Trait implementations: +impl AsMut> for Vec32 { + fn as_mut(&mut self) -> &mut Vec32 { + self + } +} + +impl AsMut<[T]> for Vec32 { + fn as_mut(&mut self) -> &mut [T] { + self + } +} + +impl AsRef> for Vec32 { + fn as_ref(&self) -> &Vec32 { + self + } +} + +impl AsRef<[T]> for Vec32 { + fn as_ref(&self) -> &[T] { + self + } +} + +impl borrow::Borrow<[T]> for Vec32 { + fn borrow(&self) -> &[T] { + &self[..] + } +} + +impl borrow::BorrowMut<[T]> for Vec32 { + fn borrow_mut(&mut self) -> &mut [T] { + &mut self[..] + } +} + +impl Default for Vec32 { + fn default() -> Self { + Self::new() + } +} + impl Drop for Vec32 { fn drop(&mut self) { unsafe { @@ -319,6 +361,20 @@ impl Drop for Vec32 { } } +impl> ops::Index for Vec32 { + type Output = I::Output; + + fn index(&self, index: I) -> &Self::Output { + ops::Index::index(&**self, index) + } +} + +impl> ops::IndexMut for Vec32 { + fn index_mut(&mut self, index: I) -> &mut Self::Output { + ops::IndexMut::index_mut(&mut **self, index) + } +} + unsafe impl Sync for Vec32 {} unsafe impl Send for Vec32 {} @@ -412,6 +468,12 @@ impl PartialOrd for Vec32 { } } +impl Ord for Vec32 { + fn cmp(&self, other: &Vec32) -> cmp::Ordering { + Ord::cmp(&**self, &**other) + } +} + impl Eq for Vec32 {} impl PartialEq for Vec32 where U: for<'a> PartialEq<&'a [T]> {