Skip to content

Commit

Permalink
Experiment
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Nov 30, 2017
1 parent d1851f3 commit 20be18b
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,19 @@ pub unsafe trait ArrayLength<T>: Unsigned {
type ArrayType;
}

trait ArrayLen2: Unsigned {
const LEN: usize;
}

unsafe impl<T> ArrayLength<T> for UTerm {
#[doc(hidden)]
type ArrayType = ();
}

impl ArrayLen2 for UTerm {
const LEN: usize = 0;
}

/// Internal type used to generate a struct of appropriate size
#[allow(dead_code)]
#[repr(C)]
Expand Down Expand Up @@ -129,12 +137,27 @@ unsafe impl<T, N: ArrayLength<T>> ArrayLength<T> for UInt<N, B1> {
type ArrayType = GenericArrayImplOdd<T, N::ArrayType>;
}

impl<N: ArrayLen2> ArrayLen2 for UInt<N, B0> {
const LEN: usize = N::LEN * 2;
}

impl<N: ArrayLen2> ArrayLen2 for UInt<N, B1> {
const LEN: usize = N::LEN * 2 + 1;
}


/// Struct representing a generic array - `GenericArray<T, N>` works like [T; N]
#[allow(dead_code)]
pub struct GenericArray<T, U: ArrayLength<T>> {
data: U::ArrayType,
}

/// Struct representing a generic array - `GenericArray<T, N>` works like [T; N]
#[allow(dead_code)]
struct GenericArray2<T, U: ArrayLen2> {
data: [T; U::LEN]

This comment has been minimized.

Copy link
@matklad

matklad Nov 30, 2017

Author Owner

This U::LEN is unresolved :(

}

impl<T, N> Deref for GenericArray<T, N>
where
N: ArrayLength<T>,
Expand Down Expand Up @@ -462,3 +485,4 @@ mod test {
assert_eq!(c, arr![i32; 3, 7, 11, 15]);
}
}

0 comments on commit 20be18b

Please sign in to comment.