@@ -6,6 +6,7 @@ use crate::io::prelude::*;
66use crate :: alloc:: Allocator ;
77use crate :: cmp;
88use crate :: io:: { self , BorrowedCursor , ErrorKind , IoSlice , IoSliceMut , SeekFrom } ;
9+ use core:: alloc;
910
1011/// A `Cursor` wraps an in-memory buffer and provides it with a
1112/// [`Seek`] implementation.
@@ -397,11 +398,12 @@ fn slice_write_vectored(
397398}
398399
399400/// Reserves the required space, and pads the vec with 0s if necessary.
400- fn reserve_and_pad < A : Allocator > (
401+ fn reserve_and_pad < A : Allocator , const COOP_PREFERRED : bool > (
401402 pos_mut : & mut u64 ,
402- vec : & mut Vec < u8 , A > ,
403+ vec : & mut Vec < u8 , A , COOP_PREFERRED > ,
403404 buf_len : usize ,
404- ) -> io:: Result < usize > {
405+ ) -> io:: Result < usize >
406+ where [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] : {
405407 let pos: usize = ( * pos_mut) . try_into ( ) . map_err ( |_| {
406408 io:: const_io_error!(
407409 ErrorKind :: InvalidInput ,
@@ -440,9 +442,10 @@ fn reserve_and_pad<A: Allocator>(
440442
441443/// Writes the slice to the vec without allocating
442444/// # Safety: vec must have buf.len() spare capacity
443- unsafe fn vec_write_unchecked < A > ( pos : usize , vec : & mut Vec < u8 , A > , buf : & [ u8 ] ) -> usize
445+ unsafe fn vec_write_unchecked < A , const COOP_PREFERRED : bool > ( pos : usize , vec : & mut Vec < u8 , A , COOP_PREFERRED > , buf : & [ u8 ] ) -> usize
444446where
445447 A : Allocator ,
448+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] :
446449{
447450 debug_assert ! ( vec. capacity( ) >= pos + buf. len( ) ) ;
448451 vec. as_mut_ptr ( ) . add ( pos) . copy_from ( buf. as_ptr ( ) , buf. len ( ) ) ;
@@ -458,9 +461,10 @@ where
458461/// This also allows for the vec body to be empty, but with a position of N.
459462/// This means that [`Write`] will pad the vec with 0 initially,
460463/// before writing anything from that point
461- fn vec_write < A > ( pos_mut : & mut u64 , vec : & mut Vec < u8 , A > , buf : & [ u8 ] ) -> io:: Result < usize >
464+ fn vec_write < A , const COOP_PREFERRED : bool > ( pos_mut : & mut u64 , vec : & mut Vec < u8 , A , COOP_PREFERRED > , buf : & [ u8 ] ) -> io:: Result < usize >
462465where
463466 A : Allocator ,
467+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] :
464468{
465469 let buf_len = buf. len ( ) ;
466470 let mut pos = reserve_and_pad ( pos_mut, vec, buf_len) ?;
@@ -489,13 +493,14 @@ where
489493/// This also allows for the vec body to be empty, but with a position of N.
490494/// This means that [`Write`] will pad the vec with 0 initially,
491495/// before writing anything from that point
492- fn vec_write_vectored < A > (
496+ fn vec_write_vectored < A , const COOP_PREFERRED : bool > (
493497 pos_mut : & mut u64 ,
494- vec : & mut Vec < u8 , A > ,
498+ vec : & mut Vec < u8 , A , COOP_PREFERRED > ,
495499 bufs : & [ IoSlice < ' _ > ] ,
496500) -> io:: Result < usize >
497501where
498502 A : Allocator ,
503+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] :
499504{
500505 // For safety reasons, we don't want this sum to overflow ever.
501506 // If this saturates, the reserve should panic to avoid any unsound writing.
@@ -543,9 +548,10 @@ impl Write for Cursor<&mut [u8]> {
543548}
544549
545550#[ stable( feature = "cursor_mut_vec" , since = "1.25.0" ) ]
546- impl < A > Write for Cursor < & mut Vec < u8 , A > >
551+ impl < A , const COOP_PREFERRED : bool > Write for Cursor < & mut Vec < u8 , A , COOP_PREFERRED > >
547552where
548553 A : Allocator ,
554+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] :
549555{
550556 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
551557 vec_write ( & mut self . pos , self . inner , buf)
@@ -567,9 +573,10 @@ where
567573}
568574
569575#[ stable( feature = "rust1" , since = "1.0.0" ) ]
570- impl < A > Write for Cursor < Vec < u8 , A > >
576+ impl < A , const COOP_PREFERRED : bool > Write for Cursor < Vec < u8 , A , COOP_PREFERRED > >
571577where
572578 A : Allocator ,
579+ [ ( ) ; alloc:: co_alloc_metadata_num_slots_with_preference :: < A > ( COOP_PREFERRED ) ] :
573580{
574581 fn write ( & mut self , buf : & [ u8 ] ) -> io:: Result < usize > {
575582 vec_write ( & mut self . pos , & mut self . inner , buf)
0 commit comments