-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Complex type composition (like an ENUMERATED in a SEQUENCE) #11
- Loading branch information
1 parent
cce4c27
commit faeb91c
Showing
5 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
use crate::syn::{Readable, ReadableType, Reader, Writable, WritableType, Writer}; | ||
use core::marker::PhantomData; | ||
|
||
pub struct Complex<V, T: Constraint = NoConstraint>(PhantomData<T>, PhantomData<V>); | ||
|
||
impl<V, T: Constraint> Default for Complex<V, T> { | ||
fn default() -> Self { | ||
Complex(Default::default(), Default::default()) | ||
} | ||
} | ||
|
||
pub trait Constraint {} | ||
|
||
#[derive(Default)] | ||
pub struct NoConstraint; | ||
|
||
impl Constraint for NoConstraint {} | ||
|
||
impl<V: Writable, C: Constraint> WritableType for Complex<V, C> { | ||
type Type = V; | ||
|
||
#[inline] | ||
fn write_value<W: Writer>( | ||
writer: &mut W, | ||
value: &Self::Type, | ||
) -> Result<(), <W as Writer>::Error> { | ||
value.write(writer) | ||
} | ||
} | ||
|
||
impl<V: Readable, C: Constraint> ReadableType for Complex<V, C> { | ||
type Type = V; | ||
|
||
#[inline] | ||
fn read_value<R: Reader>(reader: &mut R) -> Result<Self::Type, <R as Reader>::Error> { | ||
V::read(reader) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters