cargo run -- full_example.csv > output.csv
cargo run -- large_example.csv > output.csv
This is a complete implementation of the transaction engine.
The heart of the transaction engine lives in account.rs and relies on typing and 550 lines of unit tests to verify
that it's correct. accounts.rs stores an account per client.
Parsing the input is in transaction_record.rs and uses the standard Rust csv crate with relaxed parsing.
Error are defined using the thiserror crate.
Monetary values use the rust_decimal crate, which enlarges both the range and precision to covers plausible values
for fiat currency.
So main() does the following:
- Reads in the input file using a csv reader with
transaction_record.rs(csv format) andtransaction.rs(in-memory format). - Applies the transactions using
account.rs - Prints the final account state to stdout using
accounts.rs
User account state is handled by account.rs and it contains a function per transaction type to apply the transaction
to the account.
Unit tests can be run with:
cargo test
15 tests focuses on applying transactions to accounts.
2 tests focus on testing the whole engine from start to finish, they use BufReader and BufWriter
to simulate reading from a file and writing to stdout. These 2 tests live in main.rs.
full_example.csv and large_example.csv are in the repository for manual testing.
For 120000 transactions, the engine takes ~345 ms on my computer. Correctness has been the main focus so the only optimization is using BufReader/BufWriter which is also used for unit testing the code.
A csv reader is used to stream the input data so it does not need to all be loaded in memory at the same time.
Custom error types are defined using the thiserror crate.
Faulty transactions result in an error messaging being written to stderr.
The engine skips the bad transaction after omitting an error and continues with the next transaction.
No AI usage. Developed in RustRover with Auto Line Complete disabled.