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

Function error_retry_closure

examples/buffer_errors.rs:39–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

37}
38
39fn error_retry_closure() {
40 use rustix::buffer::Buffer;
41 use rustix::io;
42 use rustix::io::retry_on_intr;
43
44 fn b<B: Buffer<u8>>(b: B) -> io::Result<B::Output> {
45 unsafe { Ok(b.assume_init(0)) }
46 }
47
48 let mut event_buf = [0; 4];
49
50 // Ideally we'd write this, but it gets:
51 // "cannot move out of `event_buf`, a captured variable in an `FnMut` closure".
52 /*
53 let event_buf_slice = event_buf.as_mut_slice();
54 retry_on_intr(|| b(event_buf_slice)).unwrap();
55 */
56
57 // The fix: Add `&mut *`.
58 let event_buf_slice = event_buf.as_mut_slice();
59 retry_on_intr(|| b(&mut *event_buf_slice)).unwrap();
60}
61
62fn error_retry_closure_uninit() {
63 use rustix::buffer::Buffer;

Callers 1

mainFunction · 0.85

Calls 3

retry_on_intrFunction · 0.85
bFunction · 0.85
as_mut_sliceMethod · 0.45

Tested by

no test coverage detected