@@ -96,23 +96,22 @@ impl SendStream {
9696 Self { inner }
9797 }
9898
99- /// Write some of the buffer to the stream, potentailly blocking on flow control.
100- pub async fn write ( & mut self , buf : & [ u8 ] ) -> Result < usize , Error > {
101- Ok ( self . inner . write ( buf) . await ?)
99+ /// Write *all* of the buffer to the stream.
100+ pub async fn write ( & mut self , buf : & [ u8 ] ) -> Result < ( ) , Error > {
101+ self . inner . write_all ( buf) . await ?;
102+ Ok ( ( ) )
102103 }
103104
104- /// Write some of the given buffer to the stream, potentially blocking on flow control.
105- pub async fn write_buf < B : Buf > ( & mut self , buf : & mut B ) -> Result < usize , Error > {
106- let size = self . inner . write ( buf. chunk ( ) ) . await ?;
107- buf. advance ( size) ;
108- Ok ( size)
109- }
110-
111- /// Write the entire chunk of bytes to the stream.
105+ /// Write the given buffer to the stream, advancing the internal position.
112106 ///
113- /// More efficient for some implementations, as it avoids a copy
114- pub async fn write_chunk ( & mut self , buf : Bytes ) -> Result < ( ) , Error > {
115- Ok ( self . inner . write_chunk ( buf) . await ?)
107+ /// This may be polled to perform partial writes.
108+ pub async fn write_buf < B : Buf > ( & mut self , buf : & mut B ) -> Result < ( ) , Error > {
109+ while buf. has_remaining ( ) {
110+ let size = self . inner . write ( buf. chunk ( ) ) . await ?;
111+ buf. advance ( size) ;
112+ }
113+
114+ Ok ( ( ) )
116115 }
117116
118117 /// Set the stream's priority.
@@ -141,11 +140,15 @@ impl RecvStream {
141140 Self { inner }
142141 }
143142
144- /// Read some data into the provided buffer .
143+ /// Read the next chunk of data with the provided maximum size .
145144 ///
146- /// The number of bytes read is returned, or None if the stream is closed.
147- pub async fn read ( & mut self , buf : & mut [ u8 ] ) -> Result < Option < usize > , Error > {
148- Ok ( self . inner . read ( buf) . await ?)
145+ /// This returns a chunk of data instead of copying, which may be more efficient.
146+ pub async fn read ( & mut self , max : usize ) -> Result < Option < Bytes > , Error > {
147+ Ok ( self
148+ . inner
149+ . read_chunk ( max, true )
150+ . await ?
151+ . map ( |chunk| chunk. bytes ) )
149152 }
150153
151154 /// Read some data into the provided buffer.
@@ -166,17 +169,6 @@ impl RecvStream {
166169 Ok ( Some ( size) )
167170 }
168171
169- /// Read the next chunk of data with the provided maximum size.
170- ///
171- /// This returns a chunk of data instead of copying, which may be more efficient.
172- pub async fn read_chunk ( & mut self , max : usize ) -> Result < Option < Bytes > , Error > {
173- Ok ( self
174- . inner
175- . read_chunk ( max, true )
176- . await ?
177- . map ( |chunk| chunk. bytes ) )
178- }
179-
180172 /// Send a `STOP_SENDING` QUIC code.
181173 pub fn stop ( & mut self , code : u32 ) {
182174 self . inner . stop ( code) . ok ( ) ;
0 commit comments