diary/utils/
editing.rs

1use std::{
2    fs::File,
3    io::{self, Write},
4};
5
6use crate::errors::DiaryError;
7
8pub type StringGetter = fn(S: String) -> io::Result<String>;
9
10pub fn add_user_content_to_file(file: &mut File, content: String) -> Result<(), DiaryError> {
11    file.write_all(content.as_bytes())?;
12    Ok(())
13}
14
15#[cfg(test)]
16pub mod test {
17    use std::io;
18
19    pub fn test_string_getter(template: String) -> io::Result<String> {
20        let output = template + "Test content";
21        Ok(output)
22    }
23
24    pub fn test_empty_string_getter(_template: String) -> io::Result<String> {
25        Ok("".to_string())
26    }
27}