1- use crate :: { error:: ModuloMismatch , generic, FDBFieldValue } ;
1+ //! # Implementations for the [`zerovec`] crate
2+ //!
3+ //! [`zerovec`]: https://docs.rs/zerovec
4+
5+ use crate :: { error:: ModuloMismatch , generic, Offset } ;
26use zerovec:: ule:: { AsULE , EqULE , PlainOldULE , ULE } ;
37
48macro_rules! as_ule {
@@ -19,7 +23,7 @@ macro_rules! as_ule {
1923 } ;
2024}
2125
22- impl AsULE for FDBFieldValue {
26+ impl AsULE for super :: FieldValue {
2327 type ULE = FieldValueULE ;
2428
2529 fn as_unaligned ( & self ) -> Self :: ULE {
@@ -41,42 +45,31 @@ as_ule!(crate::aligned::RowHeaderCons = RowHeaderConsULE);
4145as_ule ! ( crate :: aligned:: RowHeader = RowHeaderULE ) ;
4246as_ule ! ( crate :: aligned:: FieldData = FieldDataULE ) ;
4347
44- macro_rules! ule_alias(
45- ( $ty: ty => $name: ident $ule: ident) => {
46- #[ cfg( feature = "pod" ) ]
47- use bytemuck_derive:: { Pod , Zeroable } ;
48-
49- #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
50- #[ cfg_attr( feature = "pod" , derive( Pod , Zeroable ) ) ]
51- #[ repr( C ) ]
52- pub struct $name( pub $ty) ;
53-
54- impl AsULE for $name {
55- type ULE = $ule;
56-
57- fn as_unaligned( & self ) -> Self :: ULE {
58- self . 0 . as_unaligned( ) . into( )
59- }
48+ impl AsULE for Offset {
49+ type ULE = OffsetULE ;
6050
61- fn from_unaligned( unaligned: & Self :: ULE ) -> Self {
62- Self ( <$ty>:: from_unaligned( unaligned. into( ) ) )
63- }
64- }
51+ fn as_unaligned ( & self ) -> Self :: ULE {
52+ self . 0 . as_unaligned ( ) . into ( )
6553 }
66- ) ;
6754
68- ule_alias ! ( u32 => Offset OffsetULE ) ;
55+ fn from_unaligned ( unaligned : & Self :: ULE ) -> Self {
56+ let p: & PlainOldULE < 4 > = unaligned. into ( ) ;
57+ Self ( u32:: from_unaligned ( p) )
58+ }
59+ }
6960
7061impl Offset {
62+ /// Get the value as an usize
7163 pub fn usize ( self ) -> usize {
7264 self . 0 as usize
7365 }
7466}
7567
7668macro_rules! ule_alias(
77- ( $name: ident<$size: literal>) => {
69+ ( $( $doc : literal ) ? $ name: ident<$size: literal>) => {
7870 #[ repr( C ) ]
7971 #[ derive( Copy , Clone , Debug ) ]
72+ $( #[ doc = $doc] ) ?
8073 pub struct $name( pub ( super ) [ u8 ; $size] ) ;
8174
8275 impl From <PlainOldULE <$size>> for $name {
@@ -93,8 +86,8 @@ macro_rules! ule_alias(
9386 } ;
9487) ;
9588
96- ule_alias ! ( OffsetULE <4 >) ;
97- ule_alias ! ( ULE32 <4 >) ;
89+ ule_alias ! ( "OffsetULE" OffsetULE <4 >) ;
90+ ule_alias ! ( "ULE32" ULE32 <4 >) ;
9891
9992impl From < u32 > for OffsetULE {
10093 fn from ( v : u32 ) -> Self {
@@ -155,14 +148,23 @@ ule_impl!(
155148 RowHeaderConsULE FieldDataULE FieldValueULE
156149) ;
157150
151+ /// The header at the beginning of the file
158152pub type HeaderULE = generic:: Header < OffsetULE , ULE32 > ;
153+ /// One entry in the table array
159154pub type TableHeaderULE = generic:: Table < OffsetULE > ;
155+ /// The definition of a table
160156pub type TableDefHeaderULE = generic:: TableDef < OffsetULE , ULE32 > ;
157+ /// One entry in the column array
161158pub type ColumnHeaderULE = generic:: Column < OffsetULE , ULE32 > ;
159+ /// The content of a table
162160pub type TableDataHeaderULE = generic:: TableData < OffsetULE , ULE32 > ;
161+ /// One entry in the buckets array
163162pub type BucketHeaderULE = generic:: BucketHeader < OffsetULE > ;
163+ /// One entry in the linked-list of rows
164164pub type RowHeaderConsULE = generic:: RowHeaderCons < OffsetULE > ;
165+ /// The data for a single row
165166pub type RowHeaderULE = generic:: RowHeader < OffsetULE , ULE32 > ;
167+ /// One entry in the list of fields
166168pub type FieldDataULE = generic:: FieldData < ULE32 , FieldValueULE > ;
167169
168170/// An FDB field value usable for unaligned reads
0 commit comments