Skip to content

Commit

Permalink
Implement indexing
Browse files Browse the repository at this point in the history
This requires Rust 1.28.0,
due to usage of [1],
so I guess we'll have to
gate it on the rustc version.

[1]: rust-lang/rust#35729
  • Loading branch information
est31 committed Mar 3, 2019
1 parent 395a590 commit 822462d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ pub mod bounds;
use bounds::AllocBound;
use std::mem::size_of;
use std::borrow::{Borrow, BorrowMut};
use std::ops::{Index,IndexMut};
use std::slice::SliceIndex;

pub struct AllocError;

Expand Down Expand Up @@ -36,3 +38,16 @@ impl<B :AllocBound, T> BorrowMut<[T]> for Bvec<B, T> {
&mut self.inner
}
}

impl<B :AllocBound, T, I :SliceIndex<[T]>> Index<I> for Bvec<B, T> {
type Output = I::Output;
fn index(&self, index :I) -> &Self::Output {
Index::index(&self.inner, index)
}
}

impl<B :AllocBound, T, I :SliceIndex<[T]>> IndexMut<I> for Bvec<B, T> {
fn index_mut(&mut self, index :I) -> &mut Self::Output {
IndexMut::index_mut(&mut *self.inner, index)
}
}

0 comments on commit 822462d

Please sign in to comment.