MCPcopy Create free account
hub / github.com/dgrunwald/rust-cpython / extract_buffer_or_sequence

Function extract_buffer_or_sequence

src/objects/sequence.rs:280–296  ·  view source on GitHub ↗
(py: Python, obj: &PyObject)

Source from the content-addressed store, hash-verified

278}
279
280pub(crate) fn extract_buffer_or_sequence<T>(py: Python, obj: &PyObject) -> PyResult<Vec<T>>
281where
282 for<'a> T: FromPyObject<'a> + buffer::Element + Copy,
283{
284 // first try buffer protocol
285 if let Ok(buf) = buffer::PyBuffer::get(py, obj) {
286 if buf.dimensions() == 1 {
287 if let Ok(v) = buf.to_vec::<T>(py) {
288 buf.release_ref(py);
289 return Ok(v);
290 }
291 }
292 buf.release_ref(py);
293 }
294 // fall back to sequence protocol
295 extract_sequence(py, obj)
296}
297
298fn extract_sequence<T>(py: Python, obj: &PyObject) -> PyResult<Vec<T>>
299where

Callers 2

extractMethod · 0.85
extractMethod · 0.85

Calls 3

extract_sequenceFunction · 0.85
dimensionsMethod · 0.80
release_refMethod · 0.45

Tested by

no test coverage detected