-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move array functions to separate module
- Loading branch information
Showing
2 changed files
with
34 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
//! Provides functions for dynamic array manipulation. | ||
/// Allocate an uninitialized array of a given size. | ||
/// | ||
/// Note that the contents of the array are not initialized and the values are undefined. | ||
pub unsafe fn allocate<T>(len: usize) -> Box<[T]> { | ||
let mut vec = Vec::with_capacity(len); | ||
vec.set_len(len); | ||
vec.into_boxed_slice() | ||
} | ||
|
||
/// Copy elements from one array to another in a range. | ||
/// | ||
/// Panics if there are less than `len` items in either of the given regions. | ||
#[inline] | ||
pub fn copy<T: Copy>(src: &[T], src_offset: usize, dest: &mut [T], dest_offset: usize, len: usize) { | ||
(&mut dest[dest_offset .. dest_offset + len]).copy_from_slice(&src[src_offset .. src_offset + len]) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters