Merge pull request #18 from traff/master

A method for accessing dictionary items.
This commit is contained in:
Daniel Grunwald 2015-07-13 20:30:08 +02:00
commit f6718a271b
1 changed files with 11 additions and 3 deletions

View File

@ -19,7 +19,7 @@
use ffi;
use python::{Python, ToPythonPointer, PythonObject};
use conversion::ToPyObject;
use objects::PyObject;
use objects::{PyObject, PyList};
use err::{self, PyResult, PyErr};
/// Represents a Python `dict`.
@ -102,5 +102,13 @@ impl <'p> PyDict<'p> {
ffi::PyDict_DelItem(self.as_ptr(), key))
})
}
}
// List of dict items.
// This is equivalent to the `dict.items()` method.
pub fn items(&self) -> PyList {
let py = self.python();
unsafe {
err::cast_from_owned_ptr_or_panic(py, ffi::PyDict_Items(self.as_ptr()))
}
}
}