From ccda716764ae84dee9f18f66e383b66c9e30b3b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Thu, 29 Jul 2021 09:56:13 +0200 Subject: list categories --- cli/src/model.rs | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'cli/src/model.rs') diff --git a/cli/src/model.rs b/cli/src/model.rs index 01b645a..c70e43d 100644 --- a/cli/src/model.rs +++ b/cli/src/model.rs @@ -4,7 +4,6 @@ use std::convert::AsRef; use std::fs; use std::hash::{Hash, Hasher}; use std::path::{Path, PathBuf}; -use std::str::FromStr; use structopt::StructOpt; use twox_hash::XxHash64; @@ -21,7 +20,7 @@ pub enum TransactionKind { //TODO Transfer, } -impl FromStr for TransactionKind { +impl std::str::FromStr for TransactionKind { type Err = String; fn from_str(s: &str) -> Result { @@ -91,6 +90,17 @@ impl Store { } Ok(()) } + + pub fn categories(&self) -> Vec { + let mut categories: Vec<_> = self + .transactions + .iter() + .map(|t| t.category.clone()) + .collect(); + categories.sort(); + categories.dedup(); + categories + } } impl Transaction { @@ -109,4 +119,3 @@ impl Transaction { h.finish() } } - -- cgit v1.2.1