Crates.io | ati |
lib.rs | ati |
version | 0.2.0 |
source | src |
created_at | 2023-12-01 07:28:03.390231 |
updated_at | 2023-12-01 09:55:43.231933 |
description | Introduces the `At` trait, which allows collections to be indexed by `u|i{8,16,32,64,128}` and `isize`. Supports Python-like negative index, where -1 is last element. |
homepage | |
repository | https://github.com/KlasafGeijerstam/ati |
max_upload_size | |
id | 1054842 |
size | 5,651 |
Vec
The ati
crate introduces the At
trait, and implements it for Vec
,
VecDeque
, [T; L]
and LinkedList
.
The At
trait adds a at
and at_mut
method, which allows collections to be
indexed by u8, u16, u32, u64, u128
, as well as i8, i16, i32, i64, i128, isize
.
Negative indexes allows for indexing in the reverse direction, exactly how the
Javascript
at
function works, or Python indexing.
use ati::At;
fn main() {
let mut v = vec![1,2,3];
assert_eq!(1, *v.at(0u8));
assert_eq!(3, *v.at(-1u128));
*v.at_mut(-1) = 5;
assert_eq!(&[1, 2, 5], &v[..]);
}