MCPcopy Create free account
hub / github.com/bytecodealliance/system-interface / advance

Function advance

src/fs/file_io_ext.rs:342–369  ·  view source on GitHub ↗

This will be obviated by [rust-lang/rust#62726]. [rust-lang/rust#62726]: https://github.com/rust-lang/rust/issues/62726.

(bufs: &'b mut [IoSlice<'a>], n: usize)

Source from the content-addressed store, hash-verified

340///
341/// [rust-lang/rust#62726]: https://github.com/rust-lang/rust/issues/62726.
342fn advance<'a, 'b>(bufs: &'b mut [IoSlice<'a>], n: usize) -> &'b mut [IoSlice<'a>] {
343 // Number of buffers to remove.
344 let mut remove = 0;
345 // Total length of all the to be removed buffers.
346 let mut accumulated_len = 0;
347 for buf in bufs.iter() {
348 if accumulated_len + buf.len() > n {
349 break;
350 } else {
351 accumulated_len += buf.len();
352 remove += 1;
353 }
354 }
355
356 #[allow(clippy::indexing_slicing)]
357 let bufs = &mut bufs[remove..];
358 if let Some(first) = bufs.first_mut() {
359 let advance_by = n - accumulated_len;
360 let mut ptr = first.as_ptr();
361 let mut len = first.len();
362 unsafe {
363 ptr = ptr.add(advance_by);
364 len -= advance_by;
365 *first = IoSlice::<'a>::new(slice::from_raw_parts::<'a>(ptr, len));
366 }
367 }
368 bufs
369}
370
371/// This will be obviated by [rust-lang/rust#62726].
372///

Callers 2

write_all_vectored_atMethod · 0.70
append_all_vectoredMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected