Crate scolapasta_aref
source ·Expand description
Functions for working with Ruby containers that respond to #[]
or “aref”.
Convert offsets to usize
indexes like this:
let data = "ABC, 123, XYZ";
let offset = -5;
let index = scolapasta_aref::offset_to_index(offset, data.len())?;
assert_eq!(index, 8);
assert_eq!(&data[index..], ", XYZ");
Functions
Convert a signed aref offset to a
usize
index into the underlying container.