Skip to content

Commit

Permalink
docs: improve documentation of rust API
Browse files Browse the repository at this point in the history
  • Loading branch information
NickCrews committed Jul 29, 2023
1 parent 4e96681 commit d11e98a
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 12 deletions.
6 changes: 4 additions & 2 deletions crates/feco3/src/cover.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ use crate::record::Record;
use crate::schemas::{LineParser, LiteralLineParser};
use crate::Error;

/// Summary information about the filing.
/// The cover line in an FecFile.
///
/// See https://github.com/NickCrews/feco3/wiki for more info.
/// See
/// [https://github.com/NickCrews/feco3/wiki](https://github.com/NickCrews/feco3/wiki)
/// for more info.
#[derive(Debug, Clone, Default)]
pub struct Cover {
/// What form is this .fec file, eg "F3X"
Expand Down
6 changes: 4 additions & 2 deletions crates/feco3/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ use std::result::Result;

use crate::schemas::LiteralLineParser;

/// The header of a FEC file.
/// The header of a FecFile.
///
/// See https://github.com/NickCrews/feco3/wiki for more info.
/// See
/// [https://github.com/NickCrews/feco3/wiki](https://github.com/NickCrews/feco3/wiki)
/// for more info.
///
/// There might be other bits of information available,
/// but currently we only parse this subset.
Expand Down
5 changes: 3 additions & 2 deletions crates/feco3/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
//! streams, or a custom source.
//!
//! FECo3 includes a framework for writing the parsed data. Currently,
//! the only supported output format is CSV, but the framework is designed
//! to be extensible to other formats.
//! writing to a directory of .csvs or .parquet files are built in,
//! but the framework is designed to be extensible to other formats.
//!
//! There are bindings for python available
//! [on the repo](https://github.com/NickCrews/feco3).
Expand All @@ -31,6 +31,7 @@ pub use crate::fec::FecFile;
pub use crate::fec::LineIter;
pub use crate::header::Header;

/// The error type for this crate.
#[derive(thiserror::Error, Debug)]
pub enum Error {
#[allow(missing_docs)]
Expand Down
8 changes: 6 additions & 2 deletions crates/feco3/src/record.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
//! Single itemization records from an .fec file.
//!
//! See https://github.com/NickCrews/feco3/wiki for more
//! See
//! [https://github.com/NickCrews/feco3/wiki](https://github.com/NickCrews/feco3/wiki)
//! for more info

use std::fmt;
use std::hash::Hash;
Expand Down Expand Up @@ -100,7 +102,9 @@ pub struct FieldSchema {

/// A parsed line of a .FEC file.
///
/// See https://github.com/NickCrews/feco3/wiki/.fec-File-Format for more.
/// See
/// [https://github.com/NickCrews/feco3/wiki](https://github.com/NickCrews/feco3/wiki)
/// for more info
#[derive(Debug, Clone)]
pub struct Record {
/// The record type code that begins the line in the .fec file, eg "SA11"
Expand Down
2 changes: 1 addition & 1 deletion crates/feco3/src/writers/arrow.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Helpers for converting [Record]s into arrow [RecordBatch]es.
//! Convert [Record]s into arrow [RecordBatch]es.
use arrow::array::{
ArrayBuilder, BooleanBuilder, Date32Builder, Float64Builder, Int64Builder, StringBuilder,
};
Expand Down
2 changes: 1 addition & 1 deletion crates/feco3/src/writers/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub trait RecordWriterFactory: Send {
fn make_writer(&mut self, schema: &RecordSchema) -> std::io::Result<Self::Writer>;
}

/// Creates [RecordWriter]s that write to a filea.
/// Creates [RecordWriter]s that write to a file.
pub trait FileRecordWriterFactory: Send {
type Writer: RecordWriter;
fn file_name(&self, form_name: String) -> String;
Expand Down
7 changes: 7 additions & 0 deletions crates/feco3/src/writers/csv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,17 @@ impl FileRecordWriterFactory for CSVFileWriterFactory {
}
}

/// Writes forms to a directory of CSV files.
///
/// Each form type gets its own file. If the form type contains a "/"
/// (which would result in a subdirectory), it is replaced with a "-".
/// For example, "SC/10" would be written to "SC-10.csv".
pub struct CSVProcessor {
multi_writer: MultiRecordWriter<MultiFileRecordWriterFactory<CSVFileWriterFactory>>,
}

impl CSVProcessor {
/// Create a new CSVProcessor that writes to the given directory.
pub fn new(out_dir: PathBuf) -> Self {
let factory = CSVFileWriterFactory;
let f2 = MultiFileRecordWriterFactory::new(out_dir, factory);
Expand All @@ -79,6 +85,7 @@ impl CSVProcessor {
}

// TODO: factor this out with ParquetProcessor.process()
/// Process the given FEC file, writing the results to the output directory.
pub fn process(&mut self, fec: &mut FecFile) -> Result<(), Error> {
let fec_version = fec.get_header()?.fec_version.clone();
let mut parser = CoercingLineParser;
Expand Down
2 changes: 1 addition & 1 deletion crates/feco3/src/writers/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! Writers for the parsed data.
//! Writers for individual [crate::record::Record]s

pub mod arrow;
pub mod base;
Expand Down
10 changes: 9 additions & 1 deletion crates/feco3/src/writers/parquet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,20 @@ impl FileRecordWriterFactory for ParquetWriterFactory {
}
}

/// Processes an entire FEC file, writing each form to a separate file.
/// Writes forms to a directory of CSV files.
///
/// Each form type gets its own file. If the form type contains a "/"
/// (which would result in a subdirectory), it is replaced with a "-".
/// For example, "SC/10" would be written to "SC-10.csv".
pub struct ParquetProcessor {
writer: MultiRecordWriter<MultiFileRecordWriterFactory<ParquetWriterFactory>>,
}

impl ParquetProcessor {
/// Create a new CSVProcessor that writes to the given directory.
///
/// `writer_props` can be used to configure the parquet writer used for
/// each file. If None, the default writer properties are used.
pub fn new(out_dir: PathBuf, writer_props: Option<WriterProperties>) -> Self {
let factory = ParquetWriterFactory {
props: writer_props,
Expand Down

0 comments on commit d11e98a

Please sign in to comment.