Skip to content

Document a few undocumented methos in Vector #9381

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 21, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/libstd/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
}

#[inline]
/// Returns an iterator over the vector
fn iter(self) -> VecIterator<'self, T> {
unsafe {
let p = vec::raw::to_ptr(self);
Expand All @@ -941,6 +942,7 @@ impl<'self,T> ImmutableVector<'self, T> for &'self [T] {
}

#[inline]
/// Returns a reversed iterator over a vector
fn rev_iter(self) -> RevIterator<'self, T> {
self.iter().invert()
}
Expand Down Expand Up @@ -1931,6 +1933,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
}

#[inline]
/// Returns an iterator that allows modifying each value
fn mut_iter(self) -> VecMutIterator<'self, T> {
unsafe {
let p = vec::raw::to_mut_ptr(self);
Expand All @@ -1947,6 +1950,7 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
}

#[inline]
/// Returns a reversed iterator that allows modifying each value
fn mut_rev_iter(self) -> MutRevIterator<'self, T> {
self.mut_iter().invert()
}
Expand Down Expand Up @@ -1988,11 +1992,13 @@ impl<'self,T> MutableVector<'self, T> for &'self mut [T] {
}

#[inline]
/// Returns an unsafe mutable pointer to the element in index
unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T {
Copy link
Member

Choose a reason for hiding this comment

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

I prefer the name raw pointer, but anyway, the point of this function is to index the vector without boundary checking, and that's the unsafe part of it.

ptr::mut_offset(self.repr().data as *mut T, index as int)
}

#[inline]
/// Unsafely sets the element in index to the value
unsafe fn unsafe_set(self, index: uint, val: T) {
*self.unsafe_mut_ref(index) = val;
}
Expand Down