From 0e033ad93f0ee15926e3910ee8269dff66c11cf5 Mon Sep 17 00:00:00 2001 From: Marcin Pajkowski Date: Wed, 24 Jul 2019 19:03:02 +0200 Subject: [PATCH] Add str.__reversed__ method --- vm/src/obj/objstr.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/vm/src/obj/objstr.rs b/vm/src/obj/objstr.rs index 890918beb..5dd3adcd2 100644 --- a/vm/src/obj/objstr.rs +++ b/vm/src/obj/objstr.rs @@ -1102,6 +1102,16 @@ impl PyString { string: zelf, } } + + #[pymethod(name = "__reversed__")] + fn reversed(zelf: PyRef, _vm: &VirtualMachine) -> PyStringReverseIterator { + let begin = zelf.value.chars().count(); + + PyStringReverseIterator { + position: Cell::new(begin), + string: zelf, + } + } } impl PyValue for PyString {