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

Method as_slice

src/objects/tuple.rs:77–88  ·  view source on GitHub ↗
(&'a self, py: Python)

Source from the content-addressed store, hash-verified

75
76 #[inline]
77 pub fn as_slice<'a>(&'a self, py: Python) -> &'a [PyObject] {
78 // This is safe because PyObject has the same memory layout as *mut ffi::PyObject,
79 // and because tuples are immutable.
80 // (We don't even need a Python token, thanks to immutability)
81 unsafe {
82 let ptr = self.0.as_ptr() as *mut ffi::PyTupleObject;
83 PyObject::borrow_from_owned_ptr_slice(slice::from_raw_parts(
84 (*ptr).ob_item.as_ptr(),
85 self.len(py),
86 ))
87 }
88 }
89
90 #[inline]
91 pub fn iter(&self, py: Python) -> slice::Iter<PyObject> {

Callers 2

iterMethod · 0.45
to_py_objectMethod · 0.45

Calls 2

as_ptrMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected