#collection #indexing #traits #index #negative #vec #linked-list

ati

引入了 At 特征,允许集合通过 u8u16u32u64u128 以及 isize 来索引。支持类似 Python 的负索引,其中 -1 是最后一个元素。

2 个不稳定版本

0.2.0 2023 年 12 月 1 日
0.1.0 2023 年 12 月 1 日

#2142 in 数据结构

MIT 许可证

6KB
109

Ati,Vec 的便捷索引

ati 包引入了 At 特征,并为 VecVecDeque[T; L]LinkedList 实现了它。该 At 特征添加了 atat_mut 方法,允许集合通过 u8, u16, u32, u64, u128 以及 i8, i16, i32, i64, i128, isize 来索引。

负索引允许反向索引,与 JavaScript 的 at 函数或 Python 索引方式相同。

示例

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[..]);
}

lib.rs:

使用 at 方法对标准集合进行便捷索引。

无运行时依赖