Relax Sized bound on Own, Ref, Mut ptrs
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by David Tolnay · committed by David Tolnay · parent a1baad2 · Browse files · 1 file·+48 added−14 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+48 added−14 removed
- other:+48 added−14 removed
Provenance
- Commit
3c32aa7- Tree
8462ea0- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
a1baad2
1 file changed+48 added−14 removed
modified:src/ptr.rs+48 added-14 removed
1 unmodified line2 use core::marker::PhantomData;3 use core::ptr::NonNull;4 5 #[repr(transparent)]6-pub struct Own<T> {6+pub struct Own<T>7+where8+ T: ?Sized,9+{10 pub ptr: NonNull<T>,11 }12 10-unsafe impl<T> Send for Own<T> {}11-unsafe impl<T> Sync for Own<T> {}12-impl<T> Copy for Own<T> {}13-impl<T> Clone for Own<T> {13+unsafe impl<T> Send for Own<T> where T: ?Sized {}14+15+unsafe impl<T> Sync for Own<T> where T: ?Sized {}16+17+impl<T> Copy for Own<T> where T: ?Sized {}18+19+impl<T> Clone for Own<T>20+where21+ T: ?Sized,22+{23 fn clone(&self) -> Self {24 *self25 }26 }27 19-impl<T> Own<T> {28+impl<T> Own<T>29+where30+ T: ?Sized,31+{32 pub fn new(ptr: Box<T>) -> Self {33 Own {34 ptr: unsafe { NonNull::new_unchecked(Box::into_raw(ptr)) },35 }24 unmodified lines60 }61 }62 63 #[repr(transparent)]52-pub struct Ref<'a, T> {64+pub struct Ref<'a, T>65+where66+ T: ?Sized,67+{68 pub ptr: NonNull<T>,69 lifetime: PhantomData<&'a T>,70 }71 57-impl<'a, T> Copy for Ref<'a, T> {}58-impl<'a, T> Clone for Ref<'a, T> {72+impl<'a, T> Copy for Ref<'a, T> where T: ?Sized {}73+74+impl<'a, T> Clone for Ref<'a, T>75+where76+ T: ?Sized,77+{78 fn clone(&self) -> Self {79 *self80 }81 }82 64-impl<'a, T> Ref<'a, T> {83+impl<'a, T> Ref<'a, T>84+where85+ T: ?Sized,86+{87 pub fn new(ptr: &'a T) -> Self {88 Ref {89 ptr: NonNull::from(ptr),90 lifetime: PhantomData,12 unmodified lines103 }104 }105 106 #[repr(transparent)]85-pub struct Mut<'a, T> {107+pub struct Mut<'a, T>108+where109+ T: ?Sized,110+{111 pub ptr: NonNull<T>,112 lifetime: PhantomData<&'a mut T>,113 }114 90-impl<'a, T> Copy for Mut<'a, T> {}91-impl<'a, T> Clone for Mut<'a, T> {115+impl<'a, T> Copy for Mut<'a, T> where T: ?Sized {}116+117+impl<'a, T> Clone for Mut<'a, T>118+where119+ T: ?Sized,120+{121 fn clone(&self) -> Self {122 *self123 }124 }125 97-impl<'a, T> Mut<'a, T> {126+impl<'a, T> Mut<'a, T>127+where128+ T: ?Sized,129+{130 pub fn new(ptr: &'a mut T) -> Self {131 Mut {132 ptr: NonNull::from(ptr),133 lifetime: PhantomData,16 unmodified lines150 151 pub unsafe fn deref_mut(self) -> &'a mut T {152 &mut *self.ptr.as_ptr()153 }154+}155 156+impl<'a, T> Mut<'a, T> {157 pub unsafe fn read(self) -> T {158 self.ptr.as_ptr().read()159 }160 }9 unmodified lines