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

Function allocate_loop

examples/buffer_errors.rs:114–129  ·  view source on GitHub ↗
(mut f: F)

Source from the content-addressed store, hash-verified

112 .unwrap();
113
114 fn allocate_loop<F: FnMut(&mut [u8]) -> io::Result<usize>>(mut f: F) -> io::Result<Vec<u8>> {
115 let mut vec: Vec<u8> = Vec::new();
116 loop {
117 let ret = f(&mut [])?;
118 vec.resize(ret, 0);
119
120 match f(&mut vec) {
121 Ok(size) => {
122 vec.truncate(size);
123 vec.shrink_to_fit();
124 return Ok(vec);
125 }
126 Err(err) => return Err(err),
127 }
128 }
129 }
130 fn f<B: Buffer<u8>>(_: B) -> Result<usize, io::Errno> {
131 Ok(0)
132 }

Callers 1

Calls 1

fFunction · 0.85

Tested by

no test coverage detected