1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
use std::{
    fs::File,
    io::{self, Write},
};

use crate::errors::DiaryError;

pub type StringGetter = fn(S: String) -> io::Result<String>;

pub fn add_user_content_to_file(file: &mut File, mut content: String) -> Result<(), DiaryError> {
    content.push('\n');
    file.write_all(content.as_bytes())?;
    Ok(())
}

#[cfg(test)]
pub mod test {
    use std::io;

    pub fn test_string_getter(template: String) -> io::Result<String> {
        let output = template + "Test content";
        Ok(output)
    }

    pub fn test_empty_string_getter(_template: String) -> io::Result<String> {
        Ok("".to_string())
    }
}