MCPcopy Create free account
hub / github.com/bytecodealliance/rustix / error_retry_closure_uninit

Function error_retry_closure_uninit

examples/buffer_errors.rs:62–87  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

60}
61
62fn error_retry_closure_uninit() {
63 use rustix::buffer::Buffer;
64 use rustix::io;
65 use std::mem::MaybeUninit;
66
67 fn b<B: Buffer<u8>>(b: B) -> io::Result<B::Output> {
68 unsafe { Ok(b.assume_init(0)) }
69 }
70
71 let mut event_buf = [MaybeUninit::<u8>::uninit(); 4];
72
73 // It's tempting to write this, but it gets:
74 // "captured variable cannot escape `FnMut` closure body".
75 /*
76 rustix::io::retry_on_intr(|| b(&mut event_buf)).unwrap();
77 */
78
79 // The fix: Don't use `retry_on_intr`, unfortunately.
80 loop {
81 match b(&mut event_buf) {
82 Ok((_init, _unini)) => break,
83 Err(io::Errno::INTR) => continue,
84 Err(err) => Err(err).unwrap(),
85 }
86 }
87}
88
89fn error_retry_indirect_closure() {
90 use rustix::buffer::Buffer;

Callers 1

mainFunction · 0.85

Calls 1

bFunction · 0.85

Tested by

no test coverage detected