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

Method pack_single

crates/vm/src/builtins/memory.rs:194–205  ·  view source on GitHub ↗
(&self, pos: usize, value: PyObjectRef, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

192 }
193
194 fn pack_single(&self, pos: usize, value: PyObjectRef, vm: &VirtualMachine) -> PyResult<()> {
195 let mut bytes = self.buffer.obj_bytes_mut();
196 // TODO: Optimize
197 let data = self.format_spec.pack(vec![value], vm).map_err(|_| {
198 vm.new_type_error(format!(
199 "memoryview: invalid type for format '{}'",
200 &self.desc.format
201 ))
202 })?;
203 bytes[pos..pos + self.desc.itemsize].copy_from_slice(&data);
204 Ok(())
205 }
206
207 fn unpack_single(&self, pos: usize, vm: &VirtualMachine) -> PyResult {
208 let bytes = self.buffer.obj_bytes();

Callers 3

setitem_by_idxMethod · 0.80
setitem_by_multi_idxMethod · 0.80
__setitem__Method · 0.80

Calls 2

obj_bytes_mutMethod · 0.45
packMethod · 0.45

Tested by

no test coverage detected