typed_index 0.2.1

A strongly typed Index that know what it is indexing
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
use crate::*;

/// Trait for marking index.
/// 
/// Allow to do `index.get(&collection)` or `index.get_mut(&mut collection)`.
pub trait IndexLike : Copy
{
    fn get<T>(self, inside : &T) -> &T::Output where T : Index<Self> { inside.index(self) }
    fn get_mut<T>(self, inside : &mut T) -> &mut T::Output where T : IndexMut<Self> { inside.index_mut(self) }
}

impl IndexLike for usize {}
impl IndexLike for isize {}
impl<Data, Idx>  IndexLike for IndexTo<Data, Idx> where Self : Copy, Data : ?Sized {}