1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
use crate::{from_stream, FromStream, ToStream};

use std::io::{Read, Result, Write};

impl<S, T: ToStream<S>, const N: usize> ToStream<S> for [T; N] {
    fn to_stream<W: Write>(&self, stream: &mut W) -> Result<()> {
        for element in self {
            element.to_stream(stream)?
        }

        Ok(())
    }
}

impl<S, T: FromStream<S> + Default + Copy, const N: usize> FromStream<S> for [T; N] {
    fn from_stream<R: Read>(stream: &mut R) -> Result<Self> {
        let mut result = [Default::default(); N];

        for element in &mut result {
            *element = from_stream(stream)?
        }

        Ok(result)
    }
}