added PyTuple::slice and PyTuple::split_from methods

This commit is contained in:
Nikolay Kim 2017-07-19 13:04:58 -07:00
parent f344c4ce3d
commit 13820f4ce3
1 changed files with 19 additions and 0 deletions

View File

@ -50,6 +50,25 @@ impl PyTuple {
} }
} }
/// Take a slice of the tuple pointed to by p from low to high and return it as a new tuple.
#[inline]
pub fn slice(&self, low: isize, high: isize) -> Py<PyTuple> {
unsafe {
let ptr = ffi::PyTuple_GetSlice(self.as_ptr(), low, high);
Py::from_owned_ptr_or_panic(ptr)
}
}
/// Take a slice of the tuple pointed to by p from low and return it as a new tuple.
#[inline]
pub fn split_from(&self, low: isize) -> Py<PyTuple> {
unsafe {
let ptr = ffi::PyTuple_GetSlice(
self.as_ptr(), low, ffi::PyTuple_GET_SIZE(self.as_ptr()));
Py::from_owned_ptr_or_panic(ptr)
}
}
/// Gets the item at the specified index. /// Gets the item at the specified index.
/// ///
/// Panics if the index is out of range. /// Panics if the index is out of range.