buddy_up_lib/
lib.rs

1//! The Buddy Up Lib contains all the brains to generate pairs from people.
2mod algorithm;
3mod input;
4mod output;
5
6use glob::GlobError;
7use glob::PatternError;
8use std::io;
9use thiserror::Error;
10
11pub use algorithm::history::*;
12pub use algorithm::*;
13pub use input::People;
14pub use output::*;
15
16use serde::Deserialize;
17use serde::Serialize;
18
19/// Defines the Errors we might encounter
20#[derive(Error, Debug)]
21pub enum BuddyError {
22    #[error("Couldn't read files.")]
23    FileRead,
24
25    #[error("Io Error")]
26    IoError(#[from] io::Error),
27
28    #[error("CSV Error")]
29    CsvError(#[from] csv::Error),
30
31    #[error("Error writing history as JSON.")]
32    JsonError(#[from] serde_json::Error),
33
34    #[error("CSV isn't formatted correctly. We expect rows of 'id,name', like '1,John'. ")]
35    CsvFormatError,
36
37    #[error("Given ID is not a number. Check input.")]
38    IdNotANumber,
39
40    #[error("The given IDs are not unique. Check input.")]
41    IdsNotUnique,
42
43    #[error("Couldn't make a History path. Check the history directory.")]
44    HistoryDirectoryError(#[from] GlobError),
45
46    #[error("Error reading history, make sure there's nothing wrong with the directory name.")]
47    PatternError(#[from] PatternError),
48}
49
50#[derive(Debug, Clone, Hash, Eq, PartialEq, Serialize, Deserialize)]
51pub struct Person {
52    pub id: usize,
53    name: String,
54}
55
56impl std::fmt::Display for Person {
57    fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
58        write!(f, "{}", self.name)
59    }
60}
61
62impl Person {
63    pub fn new(id: usize, name: String) -> Self {
64        Self { id, name }
65    }
66}