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

Method with_buffer

crates/stdlib/src/pystruct.rs:165–190  ·  view source on GitHub ↗
(
            vm: &VirtualMachine,
            format_spec: FormatSpec,
            buffer: ArgBytesLike,
        )

Source from the content-addressed store, hash-verified

163
164 impl UnpackIterator {
165 fn with_buffer(
166 vm: &VirtualMachine,
167 format_spec: FormatSpec,
168 buffer: ArgBytesLike,
169 ) -> PyResult<Self> {
170 if format_spec.size == 0 {
171 Err(new_struct_error(
172 vm,
173 "cannot iteratively unpack with a struct of length 0".to_owned(),
174 ))
175 } else if !buffer.len().is_multiple_of(format_spec.size) {
176 Err(new_struct_error(
177 vm,
178 format!(
179 "iterative unpacking requires a buffer of a multiple of {} bytes",
180 format_spec.size
181 ),
182 ))
183 } else {
184 Ok(Self {
185 format_spec,
186 buffer,
187 offset: AtomicCell::new(0),
188 })
189 }
190 }
191 }
192
193 #[pyclass(with(IterNext, Iterable), flags(DISALLOW_INSTANTIATION))]

Callers

nothing calls this directly

Calls 5

new_struct_errorFunction · 0.85
newFunction · 0.85
ErrClass · 0.50
to_ownedMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected