Skip to content

Commit e6c7dcc

Browse files
committed
More docs
1 parent 81e024a commit e6c7dcc

8 files changed

Lines changed: 88 additions & 44 deletions

File tree

modules/fdb-raw/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ version = "0.1.0"
44
edition = "2018"
55

66
[features]
7-
default = []
7+
default = ["bcast"]
88
zero = ["zerovec"]
99
pod = ["bytemuck", "bytemuck_derive"]
1010
bcast = ["bytes-cast"]

modules/fdb-raw/src/aligned.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1+
//! # "Normal" aligned versions of the FDB structures
2+
13
use crate::generic;
24

5+
/// The header at the start of the file
36
pub type Header = generic::Header<u32, u32>;
7+
/// The entry in the table array
48
pub type TableHeader = generic::Table<u32>;
9+
/// The definition of the data
510
pub type TableDefHeader = generic::TableDef<u32, u32>;
11+
/// The data of a column
612
pub type ColumnHeader = generic::Column<u32, u32>;
13+
/// The content of a table
714
pub type TableDataHeader = generic::TableData<u32, u32>;
15+
/// The entry in the bucket list
816
pub type BucketHeader = generic::BucketHeader<u32>;
17+
/// One element in the linked-list of rows
918
pub type RowHeaderCons = generic::RowHeaderCons<u32>;
19+
/// The data for a row
1020
pub type RowHeader = generic::RowHeader<u32, u32>;
21+
/// One entry in the list of fields
1122
pub type FieldData = generic::FieldData<u32, [u8; 4]>;
1223

1324
impl Header {

modules/fdb-raw/src/bcast.rs

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! # Implementations for the [`bytes_cast`] crate
2+
//!
3+
//! [`bytes_cast`]: https://docs.rs/bytes-cast
4+
5+
use crate::generic;
6+
use bytes_cast::unaligned::U32Le;
7+
8+
/// The header of the file
9+
pub type Header = generic::Header<U32Le, U32Le>;
10+
/// One entry in the [`Header::tables`] array
11+
pub type TableHeader = generic::Table<U32Le>;
12+
/// The definition of a table
13+
pub type TableDefHeader = generic::TableDef<U32Le, U32Le>;
14+
/// One entry in the [`TableDefHeader::column_list`] array
15+
pub type ColumnHeader = generic::Column<U32Le, U32Le>;
16+
/// The contents of a table
17+
pub type TableDataHeader = generic::TableData<U32Le, U32Le>;
18+
/// One entry in the [`TableDataHeader::buckets`]
19+
pub type BucketHeader = generic::BucketHeader<U32Le>;
20+
/// One entry in the linked list of rows in a [`BucketHeader`]
21+
pub type RowHeaderCons = generic::RowHeaderCons<U32Le>;
22+
/// The data for a single row
23+
pub type RowHeader = generic::RowHeader<U32Le, U32Le>;
24+
/// One entry in the [`RowHeader::fields`] array
25+
pub type FieldData = generic::FieldData<U32Le, [u8; 4]>;

modules/fdb-raw/src/error.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! ## Error types
2+
13
use core::fmt;
24

35
#[derive(Debug)]

modules/fdb-raw/src/generic.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ pub struct Array<Addr, Len> {
1313

1414
#[repr(C)]
1515
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
16+
/// The header at the start of the file
1617
pub struct Header<Addr, Len> {
1718
/// The list of tables in the database
1819
///
@@ -22,6 +23,7 @@ pub struct Header<Addr, Len> {
2223

2324
#[repr(C)]
2425
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
26+
/// One entry in the tables list
2527
pub struct Table<Addr> {
2628
/// The offset of this table definition header.
2729
pub def_header: Addr,
@@ -31,6 +33,7 @@ pub struct Table<Addr> {
3133

3234
#[repr(C)]
3335
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
36+
/// The definition of a table
3437
pub struct TableDef<Addr, Len> {
3538
/// The number of columns in this table.
3639
pub column_count: Len,
@@ -42,6 +45,7 @@ pub struct TableDef<Addr, Len> {
4245

4346
#[repr(C)]
4447
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
48+
/// One entry in a columns list
4549
pub struct Column<Addr, Ty> {
4650
/// The numeric identifier of the data type.
4751
pub data_type: Ty,
@@ -51,20 +55,23 @@ pub struct Column<Addr, Ty> {
5155

5256
#[repr(C)]
5357
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
58+
/// The content of a table
5459
pub struct TableData<Addr, Len> {
5560
/// The buckets.
5661
pub buckets: Array<Addr, Len>,
5762
}
5863

5964
#[repr(C)]
6065
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
66+
/// One entry of the bucket list
6167
pub struct BucketHeader<Addr> {
6268
/// Offset of the first element of the linked list or 0xffffffff.
6369
pub head: Addr,
6470
}
6571

6672
#[repr(C)]
6773
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
74+
/// One element of the linked list of rows
6875
pub struct RowHeaderCons<Addr> {
6976
/// The offset of the row header.
7077
pub first: Addr,
@@ -74,13 +81,15 @@ pub struct RowHeaderCons<Addr> {
7481

7582
#[repr(C)]
7683
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
84+
/// The data for a single row
7785
pub struct RowHeader<Addr, Len> {
7886
/// The fields in this row
7987
pub fields: Array<Addr, Len>,
8088
}
8189

8290
#[repr(C)]
8391
#[derive(Debug, Copy, Clone, PartialEq, Eq)]
92+
/// One entry in the fields list
8493
pub struct FieldData<Ty, Val> {
8594
/// The data type.
8695
pub data_type: Ty,

modules/fdb-raw/src/lib.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![allow(clippy::upper_case_acronyms)]
1+
#![warn(missing_docs)]
22
//! The structures, as they are serialized
33
//!
44
//! This module contains the low-level structs that make up the FDB file. These
@@ -11,11 +11,11 @@
1111
//! covers the whole 32 bits.
1212
1313
pub mod aligned;
14+
#[cfg(feature = "bcast")]
15+
pub mod bcast;
1416
pub mod error;
1517
pub mod generic;
1618
mod map;
17-
#[cfg(feature = "bcast")]
18-
pub mod unaligned;
1919
#[cfg(feature = "zero")]
2020
pub mod zero;
2121

@@ -25,7 +25,14 @@ use bytemuck_derive::{Pod, Zeroable};
2525
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
2626
#[cfg_attr(feature = "pod", derive(Pod, Zeroable))]
2727
#[repr(C)]
28-
pub struct FDBFieldValue(pub [u8; 4]);
28+
/// The value of a single field
29+
pub struct FieldValue(pub [u8; 4]);
30+
31+
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
32+
#[cfg_attr(feature = "pod", derive(Pod, Zeroable))]
33+
#[repr(C)]
34+
/// A 32-bit offset into a file
35+
pub struct Offset(pub u32);
2936

3037
#[cfg(test)]
3138
mod tests {

modules/fdb-raw/src/unaligned.rs

Lines changed: 0 additions & 12 deletions
This file was deleted.

modules/fdb-raw/src/zero.rs

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
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};
26
use zerovec::ule::{AsULE, EqULE, PlainOldULE, ULE};
37

48
macro_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);
4145
as_ule!(crate::aligned::RowHeader = RowHeaderULE);
4246
as_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

7061
impl Offset {
62+
/// Get the value as an usize
7163
pub fn usize(self) -> usize {
7264
self.0 as usize
7365
}
7466
}
7567

7668
macro_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

9992
impl 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
158152
pub type HeaderULE = generic::Header<OffsetULE, ULE32>;
153+
/// One entry in the table array
159154
pub type TableHeaderULE = generic::Table<OffsetULE>;
155+
/// The definition of a table
160156
pub type TableDefHeaderULE = generic::TableDef<OffsetULE, ULE32>;
157+
/// One entry in the column array
161158
pub type ColumnHeaderULE = generic::Column<OffsetULE, ULE32>;
159+
/// The content of a table
162160
pub type TableDataHeaderULE = generic::TableData<OffsetULE, ULE32>;
161+
/// One entry in the buckets array
163162
pub type BucketHeaderULE = generic::BucketHeader<OffsetULE>;
163+
/// One entry in the linked-list of rows
164164
pub type RowHeaderConsULE = generic::RowHeaderCons<OffsetULE>;
165+
/// The data for a single row
165166
pub type RowHeaderULE = generic::RowHeader<OffsetULE, ULE32>;
167+
/// One entry in the list of fields
166168
pub type FieldDataULE = generic::FieldData<ULE32, FieldValueULE>;
167169

168170
/// An FDB field value usable for unaligned reads

0 commit comments

Comments
 (0)