Skip to content

Commit 3aef99f

Browse files
committed
fix: dma example
1 parent 7ad628a commit 3aef99f

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

text/0000-forget-marker-trait.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,13 @@ Let's say that `Serial::read_exact` triggers a DMA transfer and returns a future
188188
fn start(serial: &mut Serial) {
189189
let mut buf = [0; 16];
190190

191-
mem::forget(serial.read_exact(&mut buf));
191+
let fut = Box::pin(serial.read_exact(&mut buf));
192+
193+
fut.poll(cx); // start dma transfer
194+
195+
// Memory of the future itself is still valid (inside the allocation),
196+
// but the buffer lives outside of it and is not protected.
197+
core::mem::forget(fut); // or `Box::leak`
192198
}
193199

194200
fn corrupted() {

0 commit comments

Comments
 (0)