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

Method items

src/objects/dict.rs:117–134  ·  view source on GitHub ↗

Returns the list of (key,value) pairs in this dictionary.

(&self, py: Python)

Source from the content-addressed store, hash-verified

115
116 /// Returns the list of (key,value) pairs in this dictionary.
117 pub fn items(&self, py: Python) -> Vec<(PyObject, PyObject)> {
118 // Note that we don't provide an iterator because
119 // PyDict_Next() is unsafe to use when the dictionary might be changed
120 // by other python code.
121 let mut vec = Vec::with_capacity(self.len(py));
122 let mut pos = 0;
123 let mut key: *mut ffi::PyObject = ptr::null_mut();
124 let mut value: *mut ffi::PyObject = ptr::null_mut();
125 unsafe {
126 while ffi::PyDict_Next(self.0.as_ptr(), &mut pos, &mut key, &mut value) != 0 {
127 vec.push((
128 PyObject::from_borrowed_ptr(py, key),
129 PyObject::from_borrowed_ptr(py, value),
130 ));
131 }
132 }
133 vec
134 }
135}
136
137/// Converts a Rust `HashMap` to a Python `dict`.

Callers 6

parse_argsFunction · 0.80
test_itemsFunction · 0.80
mainFunction · 0.80
variant_seedMethod · 0.80
runFunction · 0.80
runFunction · 0.80

Calls 2

lenMethod · 0.45
as_ptrMethod · 0.45

Tested by 2

test_itemsFunction · 0.64
runFunction · 0.64