File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -108,6 +108,26 @@ impl<'data> BorrowedBuf<'data> {
108108 }
109109 }
110110
111+ /// Returns a shared reference to the filled portion of the buffer with its original lifetime.
112+ #[ inline]
113+ pub fn into_filled ( self ) -> & ' data [ u8 ] {
114+ // SAFETY: We only slice the filled part of the buffer, which is always valid
115+ unsafe {
116+ let buf = self . buf . get_unchecked ( ..self . filled ) ;
117+ MaybeUninit :: slice_assume_init_ref ( buf)
118+ }
119+ }
120+
121+ /// Returns a mutable reference to the filled portion of the buffer with its original lifetime.
122+ #[ inline]
123+ pub fn into_filled_mut ( self ) -> & ' data mut [ u8 ] {
124+ // SAFETY: We only slice the filled part of the buffer, which is always valid
125+ unsafe {
126+ let buf = self . buf . get_unchecked_mut ( ..self . filled ) ;
127+ MaybeUninit :: slice_assume_init_mut ( buf)
128+ }
129+ }
130+
111131 /// Returns a cursor over the unfilled part of the buffer.
112132 #[ inline]
113133 pub fn unfilled < ' this > ( & ' this mut self ) -> BorrowedCursor < ' this > {
You can’t perform that action at this time.
0 commit comments