Skip to content

Commit

Permalink
Auto-implement Readable and Writable for all sequence::Constraint
Browse files Browse the repository at this point in the history
  • Loading branch information
kellerkindt committed Apr 22, 2020
1 parent 325c96f commit 0db9fe9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
11 changes: 0 additions & 11 deletions src/syn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,17 +117,6 @@ mod tests {
}
}

impl Writable for Whatever {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), <W as Writer>::Error> {
AsnDefWhatever::write_value(writer, self)
}
}
impl Readable for Whatever {
fn read<R: Reader>(reader: &mut R) -> Result<Self, <R as Reader>::Error> {
AsnDefWhatever::read_value(reader)
}
}

#[derive(Default)]
struct PrintlnWriter(usize);

Expand Down
14 changes: 13 additions & 1 deletion src/syn/sequence.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::syn::{ReadableType, Reader, WritableType, Writer};
use crate::syn::{Readable, ReadableType, Reader, Writable, WritableType, Writer};
use core::marker::PhantomData;

pub struct Sequence<T: Constraint>(PhantomData<T>);
Expand Down Expand Up @@ -43,3 +43,15 @@ where
reader.read_sequence::<C, Self::Type, _>(C::read_seq)
}
}

impl<C: Constraint> Writable for C {
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), <W as Writer>::Error> {
Sequence::<C>::write_value(writer, self)
}
}

impl<C: Constraint> Readable for C {
fn read<R: Reader>(reader: &mut R) -> Result<Self, <R as Reader>::Error> {
Sequence::<C>::read_value(reader)
}
}

0 comments on commit 0db9fe9

Please sign in to comment.