Add str.__reversed__ method

This commit is contained in:
Marcin Pajkowski
2019-07-24 19:03:02 +02:00
parent 6aeec34df0
commit 0e033ad93f

View File

@@ -1102,6 +1102,16 @@ impl PyString {
string: zelf,
}
}
#[pymethod(name = "__reversed__")]
fn reversed(zelf: PyRef<Self>, _vm: &VirtualMachine) -> PyStringReverseIterator {
let begin = zelf.value.chars().count();
PyStringReverseIterator {
position: Cell::new(begin),
string: zelf,
}
}
}
impl PyValue for PyString {