From 24c4ea71b11ce6c07d92dd6876fec6a9b0f6ed10 Mon Sep 17 00:00:00 2001 From: ZhangYong Date: Sat, 3 Jun 2023 17:44:25 +0800 Subject: [PATCH] sync/pipe: write all user data to pipe sync/pipe: add write_all function --- embassy-sync/src/pipe.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) 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 WriteFuture { pipe: self, buf } } + /// Write all bytes to the pipe. + /// + /// This method writes all bytes from `buf` into the pipe + pub async fn write_all(&self, mut buf: &[u8]) { + while !buf.is_empty() { + let n = self.write(buf).await; + buf = &buf[n..]; + } + } + /// Attempt to immediately write some bytes to the pipe. /// /// This method will either write a nonzero amount of bytes to the pipe immediately,