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

Method new

src/objects/tuple.rs:35–45  ·  view source on GitHub ↗

Construct a new tuple with the given elements.

(py: Python, elements: &[PyObject])

Source from the content-addressed store, hash-verified

33impl PyTuple {
34 /// Construct a new tuple with the given elements.
35 pub fn new(py: Python, elements: &[PyObject]) -> PyTuple {
36 unsafe {
37 let len = elements.len();
38 let ptr = ffi::PyTuple_New(len as Py_ssize_t);
39 let t = err::result_cast_from_owned_ptr::<PyTuple>(py, ptr).unwrap();
40 for (i, e) in elements.iter().enumerate() {
41 ffi::PyTuple_SetItem(ptr, i as Py_ssize_t, e.steal_ptr(py));
42 }
43 t
44 }
45 }
46
47 /// Retrieves the empty tuple.
48 pub fn empty(py: Python) -> PyTuple {

Callers

nothing calls this directly

Calls 3

lenMethod · 0.45
iterMethod · 0.45
steal_ptrMethod · 0.45

Tested by

no test coverage detected