(&mut self, vm: &VirtualMachine)
| 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)] |
no test coverage detected