Improving Wrapper API
// If not, see <https://opensource.org/licenses/MIT>.
+use core::borrow::{Borrow, BorrowMut};
use std::{
ops::{Deref, DerefMut, Index, Range, RangeTo, RangeFrom, RangeFull},
marker::PhantomData,
@@ -20,13 +21,13 @@ use std::{
// TODO: Do a macro for simple wrapper type creations (automate phantom data generation)
-#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Debug)]
+#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Default)]
pub struct Wrapper<T, Z>(T, PhantomData<Z>);
impl<T, Z> Wrapper<T, Z> {
#[inline]
pub fn from_inner(inner: T) -> Self {
- Wrapper::from(inner)
+ Self::from(inner)
}
#[inline]
@@ -35,6 +36,18 @@ impl<T, Z> Wrapper<T, Z> {
}
}
+impl<T, Z> Borrow<T> for Wrapper<T, Z> {
+ fn borrow(&self) -> &T {
+ &self.0
+ }
+}
+
+impl<T, Z> BorrowMut<T> for Wrapper<T, Z> {
+ fn borrow_mut(&mut self) -> &mut T {
+ &mut self.0
+ }
+}
+
impl<T, Z> AsMut<T> for Wrapper<T, Z> {
#[inline]
fn as_mut(&mut self) -> &mut T {
