Skip to content
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

Minor fixes #4

Merged
merged 2 commits into from
Sep 4, 2015
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
18 changes: 12 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ extern crate quickcheck;
/// You can use `array_ref` to generate an array reference to a subset
/// of a sliceable bit of data (which could be an array, or a slice,
/// or a Vec).
///
/// **Panics** if the slice is out of bounds.
#[macro_export]
macro_rules! array_ref {
($arr:expr, $offset:expr, $len:expr) => {{
Expand All @@ -29,7 +31,8 @@ macro_rules! array_ref {
unsafe fn as_array<T>(slice: &[T]) -> &[T; $len] {
&*(slice.as_ptr() as *const [_; $len])
}
let slice = & $arr[$offset..$offset+$len];
let offset = $offset;
let slice = & $arr[offset..offset + $len];
unsafe {
as_array(slice)
}
Expand All @@ -47,7 +50,7 @@ macro_rules! array_refs {
#[inline]
#[allow(unused_assignments)]
unsafe fn as_arrays<T>(a: &[T; $( $len + )* 0 ]) -> ( $( &[T; $len], )* ) {
let mut p = a.as_ptr() as *const T;
let mut p = a.as_ptr();
( $( {
let aref = &*(p as *const [T; $len]);
p = p.offset($len);
Expand All @@ -73,8 +76,8 @@ macro_rules! mut_array_refs {
{
#[inline]
#[allow(unused_assignments)]
unsafe fn as_arrays<T>(a: &mut[T; $( $len + )* 0 ]) -> ( $( &mut[T; $len], )* ) {
let mut p = a.as_ptr() as *mut T;
unsafe fn as_arrays<T>(a: &mut [T; $( $len + )* 0 ]) -> ( $( &mut [T; $len], )* ) {
let mut p = a.as_mut_ptr();
( $( {
let aref = &mut *(p as *mut [T; $len]);
p = p.offset($len);
Expand All @@ -92,15 +95,18 @@ macro_rules! mut_array_refs {
/// You can use `array_mut_ref` to generate a mutable array reference
/// to a subset of a sliceable bit of data (which could be an array,
/// or a slice, or a Vec).
///
/// **Panics** if the slice is out of bounds.
#[macro_export]
macro_rules! array_mut_ref {
($arr:expr, $offset:expr, $len:expr) => {{
{
#[inline]
unsafe fn as_array<T>(slice: &mut[T]) -> &mut[T; $len] {
unsafe fn as_array<T>(slice: &mut [T]) -> &mut [T; $len] {
&mut *(slice.as_mut_ptr() as *mut [_; $len])
}
let slice = &mut $arr[$offset..$offset+$len];
let offset = $offset;
let slice = &mut $arr[offset..offset + $len];
unsafe {
as_array(slice)
}
Expand Down