@@ -4760,6 +4760,21 @@ pub struct Ref<B, T: ?Sized>(
4760
4760
PhantomData < T > ,
4761
4761
) ;
4762
4762
4763
+ impl < B : ByteSlice + Clone , T : ?Sized > Clone for Ref < B , T > {
4764
+ #[ inline]
4765
+ fn clone ( & self ) -> Ref < B , T > {
4766
+ // INVARIANTS: By invariant on `self.0`, it is aligned to `T`'s
4767
+ // alignment and its size corresponds to a valid size for `T`. By safety
4768
+ // invariant on `ByteSlice`, these properties are preserved by `clone`.
4769
+ Ref ( self . 0 . clone ( ) , PhantomData )
4770
+ }
4771
+ }
4772
+
4773
+ // INVARIANTS: By invariant on `Ref`'s `.0` field, it is aligned to `T`'s
4774
+ // alignment and its size corresponds to a valid size for `T`. By safety
4775
+ // invariant on `ByteSlice`, these properties are preserved by `Copy`.
4776
+ impl < B : ByteSlice + Copy , T : ?Sized > Copy for Ref < B , T > { }
4777
+
4763
4778
impl < B , T > Ref < B , T >
4764
4779
where
4765
4780
B : ByteSlice ,
@@ -5568,6 +5583,15 @@ mod sealed {
5568
5583
/// operation in order for the utilities in this crate to perform as designed.
5569
5584
///
5570
5585
/// [`split_at`]: crate::ByteSlice::split_at
5586
+ ///
5587
+ /// # Safety
5588
+ ///
5589
+ /// If `Self: Clone` or `Self: Copy`, these implementations must be "stable" in
5590
+ /// the sense that, given `bytes: Self`, if `bytes.deref()` produces a byte
5591
+ /// slice of a given address and length, any copy or clone of `bytes`,
5592
+ /// `bytes_new`, must also produce a byte slice of the same address and length
5593
+ /// from `bytes_new.deref()`.
5594
+ ///
5571
5595
// It may seem overkill to go to this length to ensure that this doc link never
5572
5596
// breaks. We do this because it simplifies CI - it means that generating docs
5573
5597
// always succeeds, so we don't need special logic to only generate docs under
0 commit comments