I am currently building a TUI where I would like to put the current selected element in a cursor like structure. However I would like it to be circular so that when I reach the end it just starts at the beginning again.
I have modified the following example from the std docs to include the behavior I would like.
use std::io::Cursor;
use std::io::prelude::*;
use std::io::SeekFrom;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(buff.position(), 4);
buff.seek(SeekFrom::Current(1)).unwrap();
assert_eq!(buff.position(), 0);
What is the most idiomatic way to do this in rust?