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

Function error_array_by_value

examples/buffer_errors.rs:154–173  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

152}
153
154fn error_array_by_value() {
155 use rustix::buffer::Buffer;
156
157 fn read<B: Buffer<u8>>(b: B) -> B::Output {
158 unsafe { b.assume_init(0) }
159 }
160
161 // This code is erroneously attempts to pass a buffer by value, but it
162 // confusingly gets two error messages:
163 // "the trait bound `[{integer}; 3]: Buffer<u8>` is not satisfied", and
164 // "the trait bound `[{integer}; 3]: buffer::private::Sealed<u8>` is not satisfied".
165 /*
166 let mut buf = [0, 0, 0];
167 read(buf);
168 */
169
170 // The fix: pass the buffer by reference.
171 let mut buf = [0, 0, 0];
172 read(&mut buf);
173}

Callers 1

mainFunction · 0.85

Calls 1

readFunction · 0.70

Tested by

no test coverage detected