MCPcopy Index your code
hub / github.com/RustPython/RustPython / take

Method take

crates/vm/src/stdlib/_io.rs:2535–2548  ·  view source on GitHub ↗
(&mut self, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

2533 }
2534 }
2535 fn take(&mut self, vm: &VirtualMachine) -> PyBytesRef {
2536 let Self { num_bytes, data } = core::mem::take(self);
2537 if let PendingWritesData::One(PendingWrite::Bytes(b)) = data {
2538 return b;
2539 }
2540 let writes_iter = match data {
2541 PendingWritesData::None => itertools::Either::Left(vec![].into_iter()),
2542 PendingWritesData::One(write) => itertools::Either::Right(core::iter::once(write)),
2543 PendingWritesData::Many(writes) => itertools::Either::Left(writes.into_iter()),
2544 };
2545 let mut buf = Vec::with_capacity(num_bytes);
2546 writes_iter.for_each(|chunk| buf.extend_from_slice(chunk.as_bytes()));
2547 PyBytes::from(buf).into_ref(&vm.ctx)
2548 }
2549 }
2550
2551 #[derive(Default, Debug)]

Callers 15

sliceMethod · 0.45
repr_wtf8Method · 0.45
raw_writeMethod · 0.45
raw_readMethod · 0.45
detachMethod · 0.45
writeMethod · 0.45
readlineMethod · 0.45
write_pendingMethod · 0.45
nextMethod · 0.45
_mulMethod · 0.45
closeMethod · 0.45
nextMethod · 0.45

Calls 7

takeFunction · 0.85
onceFunction · 0.85
LeftClass · 0.50
RightClass · 0.50
into_iterMethod · 0.45
as_bytesMethod · 0.45
into_refMethod · 0.45

Tested by

no test coverage detected