This was spurred by noticing a trivial case of UB in the original code:
all one needed was an out-of-bounds index on any of several methods with tokens or segment indexes on the state to cause UB.
I took this opportunity to consolidate methods into Rust structs that verify their index before use.