From 13820f4ce3da80247e3229deb3c6098f207007ce Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 19 Jul 2017 13:04:58 -0700 Subject: [PATCH] added PyTuple::slice and PyTuple::split_from methods --- src/objects/tuple.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/objects/tuple.rs b/src/objects/tuple.rs index 2c455a9a..533b3af1 100644 --- a/src/objects/tuple.rs +++ b/src/objects/tuple.rs @@ -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 { + 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 { + 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. /// /// Panics if the index is out of range.