rs_ach/
lib.rs

1//! # rs-ach
2//!
3//! ACH (Automated Clearing House) file parser for Rust.
4//!
5//! This crate provides a safe interface for parsing ACH files
6//! following the NACHA (National Automated Clearing House Association) specifications.
7//!
8//! ## Features
9//!
10//! - Parse ACH file headers and batch records
11//! - Support for PPD, CCD, and other standard entry class codes
12//! - Entry detail records with addenda support
13//! - Type-safe parsing with comprehensive error handling
14//! - Zero-copy parsing where possible
15//!
16//! ## Example
17//!
18//! ```no_run
19//! use rs_ach::AchFile;
20//!
21//! let ach_content = std::fs::read_to_string("sample.ach").unwrap();
22//! let ach_file = AchFile::parse(&ach_content).unwrap();
23//!
24//! for batch in &ach_file.batches {
25//!     println!("Batch: {}", batch.header.company_name);
26//!     for entry in &batch.entries {
27//!         println!("  Entry: {} - ${}", entry.individual_name, entry.amount);
28//!     }
29//! }
30//! ```
31
32mod error;
33mod parser;
34mod records;
35
36pub use error::AchError;
37pub use records::{Addenda, BatchControl, BatchHeader, EntryDetail, FileControl, FileHeader};
38
39/// Represents a complete ACH file with file header, batches, and file control.
40#[derive(Debug, Clone)]
41pub struct AchFile<'a> {
42    /// File header record (record type 1)
43    pub file_header: FileHeader<'a>,
44
45    /// Collection of batches in the file
46    pub batches: Vec<Batch<'a>>,
47
48    /// File control record (record type 9)
49    pub file_control: FileControl,
50}
51
52impl<'a> AchFile<'a> {
53    /// Parse an ACH file from a string.
54    ///
55    /// # Arguments
56    ///
57    /// * `content` - The complete ACH file content as a string
58    ///
59    /// # Returns
60    ///
61    /// Returns a parsed `AchFile` on success, or an `AchError` if parsing fails.
62    ///
63    /// # Example
64    ///
65    /// ```no_run
66    /// use rs_ach::AchFile;
67    ///
68    /// let ach_content = std::fs::read_to_string("sample.ach").unwrap();
69    /// let ach_file = AchFile::parse(&ach_content).unwrap();
70    /// ```
71    pub fn parse(content: &'a str) -> Result<Self, AchError> {
72        parser::parse_ach_file(content)
73    }
74}
75
76/// Represents a batch within an ACH file.
77#[derive(Debug, Clone)]
78pub struct Batch<'a> {
79    /// Batch header record (record type 5)
80    pub header: BatchHeader<'a>,
81
82    /// Collection of entry detail records
83    pub entries: Vec<EntryDetail<'a>>,
84
85    /// Batch control record (record type 8)
86    pub control: BatchControl,
87}