diff options
| author | ZhangYong <[email protected]> | 2023-06-03 17:44:25 +0800 |
|---|---|---|
| committer | cumthugo <[email protected]> | 2023-06-04 22:29:59 +0800 |
| commit | 24c4ea71b11ce6c07d92dd6876fec6a9b0f6ed10 (patch) | |
| tree | 4f39603c4f5992865c8cf0ec2a3c6ef185a6d241 /embassy-sync/src | |
| parent | f2c2536cf3d67e4e28616f631b6bdde789b15560 (diff) | |
sync/pipe: write all user data to pipe
sync/pipe: add write_all function
Diffstat (limited to 'embassy-sync/src')
| -rw-r--r-- | embassy-sync/src/pipe.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/embassy-sync/src/pipe.rs b/embassy-sync/src/pipe.rs index ee27cdec8..db6ebb08b 100644 --- a/embassy-sync/src/pipe.rs +++ b/embassy-sync/src/pipe.rs | |||
| @@ -294,6 +294,16 @@ where | |||
| 294 | WriteFuture { pipe: self, buf } | 294 | WriteFuture { pipe: self, buf } |
| 295 | } | 295 | } |
| 296 | 296 | ||
| 297 | /// Write all bytes to the pipe. | ||
| 298 | /// | ||
| 299 | /// This method writes all bytes from `buf` into the pipe | ||
| 300 | pub async fn write_all(&self, mut buf: &[u8]) { | ||
| 301 | while !buf.is_empty() { | ||
| 302 | let n = self.write(buf).await; | ||
| 303 | buf = &buf[n..]; | ||
| 304 | } | ||
| 305 | } | ||
| 306 | |||
| 297 | /// Attempt to immediately write some bytes to the pipe. | 307 | /// Attempt to immediately write some bytes to the pipe. |
| 298 | /// | 308 | /// |
| 299 | /// This method will either write a nonzero amount of bytes to the pipe immediately, | 309 | /// This method will either write a nonzero amount of bytes to the pipe immediately, |
