Skip to main content

tackler_core/export/
accounts_exporter.rs

1/*
2 * Tackler-NG 2026
3 * SPDX-License-Identifier: Apache-2.0
4 */
5use crate::model::AccountTreeNode;
6use crate::{export::Export, kernel::Settings, model::TxnSet, tackler};
7use std::sync::Arc;
8use std::{collections::BTreeSet, io};
9
10pub struct AccountsExporter {}
11
12impl Export for AccountsExporter {
13    fn write_export<W: io::Write + ?Sized>(
14        &self,
15        _cfg: &Settings,
16        writer: &mut W,
17        txn_data: &TxnSet<'_>,
18    ) -> Result<(), tackler::Error> {
19        // This can't be a String based set because natural sort won't work with numerical accounts
20        // Below is natural sort order for the following account names:
21        //    "E:01234567:Sweets:Ice·Cream",
22        //    "E:0123:567:Sweets:Ice·Cream",
23        // which is in wrong order ("E:0123:..." should come first)
24        let mut accounts: BTreeSet<Arc<AccountTreeNode>> = BTreeSet::new();
25        for txn in &txn_data.txns {
26            for post in &txn.posts {
27                accounts.insert(post.acctn.atn.clone());
28            }
29        }
30
31        writeln!(writer, "accounts = [")?;
32
33        for i in accounts {
34            writeln!(writer, "   \"{i}\",")?;
35        }
36        writeln!(writer, "]")?;
37        Ok(())
38    }
39}