Skip to content

Commit

Permalink
Update the const generics example a little
Browse files Browse the repository at this point in the history
IDK whether it ever compiled but with recent compilers
it didn't compile.

This commit fixes a few compilation errors but one,
regarding the array initializer [T::default(); N], remains.
See rust-lang/rust#43408
  • Loading branch information
est31 committed Oct 2, 2019
1 parent 64b2529 commit ce075a7
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/const_generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ impl<'de, T, const N: usize> BigArray<'de> for [T; N]
seq.end()
}

fn deserialize<D>(deserializer: D) -> result::Result<[T; N], D::Error>
fn deserialize<D>(deserializer: D) -> result::Result<Self, D::Error>
where D: Deserializer<'de>
{
struct ArrayVisitor<T> {
element: PhantomData<T>,
}

impl<'de, T> Visitor<'de> for ArrayVisitor<T>
impl<'de, T, const N: usize> Visitor<'de> for ArrayVisitor<[T; N]>
where T: Default + Copy + Deserialize<'de>
{
type Value = [T; N];
Expand Down Expand Up @@ -59,7 +59,7 @@ impl<'de, T, const N: usize> BigArray<'de> for [T; N]
fn visit_seq<A>(self, mut seq: A) -> result::Result<[T; N], A::Error>
where A: SeqAccess<'de>
{
let mut arr = [T::default(); N];
let mut arr: [T; N] = [T::default(); N];
for i in 0..N {
arr[i] = seq.next_element()?
.ok_or_else(|| Error::invalid_length(i, &self))?;
Expand Down

0 comments on commit ce075a7

Please sign in to comment.