2

Is it possible to create custom data types in rust that can be indexed like Vec and Slice? If yes which Traits do I need to implement?

Example for indexed access:

let mut vec = vec![1, 2, 3];
assert_eq!(vec[1], 2);
starblue
  • 55,348
  • 14
  • 97
  • 151
jonathan-dev
  • 330
  • 1
  • 3
  • 16

1 Answers1

2

Yes, the traits are called Index and IndexMut.

starblue
  • 55,348
  • 14
  • 97
  • 151