Skip to content

SmallBitVec::range method (alternative to impl Index<Range<usize>>)#11

Merged
mbrubeck merged 4 commits intoservo:masterfrom
dbkaplun:vec-methods-range
Apr 17, 2018
Merged

SmallBitVec::range method (alternative to impl Index<Range<usize>>)#11
mbrubeck merged 4 commits intoservo:masterfrom
dbkaplun:vec-methods-range

Conversation

@dbkaplun
Copy link
Contributor

No description provided.

Copy link
Collaborator

@mbrubeck mbrubeck left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! One suggested change, below:

src/lib.rs Outdated

#[inline]
fn index(&self, i: usize) -> &bool {
&self.vec[i + self.range.start]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this should panic when i + start >= end

/// assert_eq!(r[1], true);
/// ```
pub fn range(&self, range: Range<usize>) -> VecRange {
VecRange { vec: &self, range }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should panic if either end of the range is greater than self.len().

@dbkaplun
Copy link
Contributor Author

@mbrubeck ready for review

@mbrubeck mbrubeck merged commit 5933346 into servo:master Apr 17, 2018
@dbkaplun dbkaplun deleted the vec-methods-range branch April 17, 2018 23:38
mbrubeck added a commit that referenced this pull request Apr 17, 2018
* Added `range` method for slicing a vector by a range of indices (#11)
* Some code cleanup and testing improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants