1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
use std::borrow::{Borrow, BorrowMut}; use std::cmp; use std::convert; use std::fmt; use std::ops; use super::Ref; impl<'a, T> ops::Deref for Ref<'a, T> { type Target = T; #[inline(always)] fn deref(&self) -> &T { self.ptr } } impl<'a, T> ops::DerefMut for Ref<'a, T> { #[inline(always)] fn deref_mut(&mut self) -> &mut T { self.ptr } } impl<'a, T> fmt::Pointer for Ref<'a, T> { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { write!(f, "{:p}", self.ptr) } } impl<'a, T> fmt::Debug for Ref<'a, T> where T: fmt::Debug { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { <T as fmt::Debug>::fmt(self, f) } } impl<'a, T> fmt::Display for Ref<'a, T> where T: fmt::Display { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { <T as fmt::Display>::fmt(self, f) } } impl<'a, T> PartialEq for Ref<'a, T> where T: PartialEq<T> { fn eq(&self, other: &Ref<'a, T>) -> bool { PartialEq::eq(self.ptr, other.ptr) } fn ne(&self, other: &Ref<'a, T>) -> bool { PartialEq::ne(self.ptr, other.ptr) } } impl<'a, T> Eq for Ref<'a, T> where T: Eq {} impl<'a, T> Ord for Ref<'a, T> where T: Ord { fn cmp(&self, other: &Ref<'a, T>) -> cmp::Ordering { Ord::cmp(self.ptr, other.ptr) } } impl<'a, T> PartialOrd for Ref<'a, T> where T: PartialOrd { fn partial_cmp(&self, other: &Ref<'a, T>) -> Option<cmp::Ordering> { PartialOrd::partial_cmp(self.ptr, other.ptr) } fn le(&self, other: &Ref<'a, T>) -> bool { PartialOrd::le(self.ptr, other.ptr) } fn lt(&self, other: &Ref<'a, T>) -> bool { PartialOrd::le(self.ptr, other.ptr) } fn gt(&self, other: &Ref<'a, T>) -> bool { PartialOrd::le(self.ptr, other.ptr) } fn ge(&self, other: &Ref<'a, T>) -> bool { PartialOrd::le(self.ptr, other.ptr) } } impl<'a, T> convert::AsMut<T> for Ref<'a, T> { fn as_mut(&mut self) -> &mut T { self.ptr } } impl<'a, T> convert::AsRef<T> for Ref<'a, T> { fn as_ref(&self) -> &T { self.ptr } } impl<'a, T> Borrow<T> for Ref<'a, T> { fn borrow(&self) -> &T { self.ptr } } impl<'a, T> BorrowMut<T> for Ref<'a, T> { fn borrow_mut(&mut self) -> &mut T { self.ptr } } #[cfg(test)] mod tests { #[test] fn test() { } }