aboutsummaryrefslogtreecommitdiff
path: root/embassy-hal-common/src/atomic_ring_buffer.rs
diff options
context:
space:
mode:
authorDario Nieuwenhuis <[email protected]>2022-12-19 01:16:41 +0100
committerDario Nieuwenhuis <[email protected]>2022-12-19 01:22:41 +0100
commit5b72410828309bd0d37c8f85c0fb4f88d2a105f8 (patch)
tree504471b4033ca776ba19cc3146f53a54b4d188d1 /embassy-hal-common/src/atomic_ring_buffer.rs
parentfeaeb533fb5963e9d603ccb5143662b21daed2d8 (diff)
hal-common/atomic_ring_buffer: Add push_slice, pop_slice.
Diffstat (limited to 'embassy-hal-common/src/atomic_ring_buffer.rs')
-rw-r--r--embassy-hal-common/src/atomic_ring_buffer.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/embassy-hal-common/src/atomic_ring_buffer.rs b/embassy-hal-common/src/atomic_ring_buffer.rs
index 3e90b0870..a8a6a2166 100644
--- a/embassy-hal-common/src/atomic_ring_buffer.rs
+++ b/embassy-hal-common/src/atomic_ring_buffer.rs
@@ -137,6 +137,14 @@ impl<'a> Writer<'a> {
137 137
138 /// Get a buffer where data can be pushed to. 138 /// Get a buffer where data can be pushed to.
139 /// 139 ///
140 /// Equivalent to [`Self::push_buf`] but returns a slice.
141 pub fn push_slice(&mut self) -> &mut [u8] {
142 let (data, len) = self.push_buf();
143 unsafe { slice::from_raw_parts_mut(data, len) }
144 }
145
146 /// Get a buffer where data can be pushed to.
147 ///
140 /// Write data to the start of the buffer, then call `push_done` with 148 /// Write data to the start of the buffer, then call `push_done` with
141 /// however many bytes you've pushed. 149 /// however many bytes you've pushed.
142 /// 150 ///
@@ -206,6 +214,14 @@ impl<'a> Reader<'a> {
206 214
207 /// Get a buffer where data can be popped from. 215 /// Get a buffer where data can be popped from.
208 /// 216 ///
217 /// Equivalent to [`Self::pop_buf`] but returns a slice.
218 pub fn pop_slice(&mut self) -> &mut [u8] {
219 let (data, len) = self.pop_buf();
220 unsafe { slice::from_raw_parts_mut(data, len) }
221 }
222
223 /// Get a buffer where data can be popped from.
224 ///
209 /// Read data from the start of the buffer, then call `pop_done` with 225 /// Read data from the start of the buffer, then call `pop_done` with
210 /// however many bytes you've processed. 226 /// however many bytes you've processed.
211 /// 227 ///