pub fn add(
    opts: &AddOptions,
    diary: &Diary,
    date: &Date<Local>,
    string_getter: editing::StringGetter,
) -> Result<(), DiaryError> {
    let file = match diary.get_entry_file(date) {
        Ok(file) => file,
        Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
            return Err(DiaryError::NoEntry { source: Some(e) })
        }
        Err(e) => return Err(e.into()), // uncovered.
    };

    let content = string_getter("".to_owned())?;

    let tag_result = opts.tag.map(|tag| diary.file_type().tag(tag.to_owned()));

    add_content(file, content, tag_result)
}
/// Adds user provided content to a diary entry.
///
/// # Arguments
///
/// * `opts` - The options available to the add function.
/// * `diary` - Struct representing the diary.
/// * `date` - The date of the entry to add to.
/// * `string_getter` - The function that obtains the string to add to the file.
///
/// # Returns
///
/// The unit if adding the content was successful, a DiaryError otherwise.
Adds user provided content to a diary entry.
Adds user provided content to a diary entry .
pub fn add(
    opts: &AddOptions,
    diary: &Diary,
    date: &Date<Local>,
    string_getter: editing::StringGetter,
) -> Result<(), DiaryError> {
    let file = match diary.get_entry_file(date) {
        Ok(file) => file,
        Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
            return Err(DiaryError::NoEntry { source: Some(e) })
        }
        Err(e) => return Err(e.into()), // uncovered.
    };
    let content = string_getter("".to_owned())?;
    let tag_result = opts.tag.map(|tag| diary.file_type().tag(tag.to_owned()));
    add_content(file, content, tag_result)
}
pub fn add ( opts : & AddOptions , diary : & Diary , date : & Date < Local > , string_getter : editing :: StringGetter , ) -> Result < ( ) , DiaryError > { let file = match diary . get_entry_file ( date ) { Ok ( file ) => file , Err ( e ) if e . kind ( ) == std :: io :: ErrorKind :: NotFound => { return Err ( DiaryError :: NoEntry { source : Some ( e ) } ) } Err ( e ) => return Err ( e . into ( ) ) , // uncovered. } ; let content = string_getter ( " " . to_owned ( ) ) ? ; let tag_result = opts . tag . map ( | tag | diary . file_type ( ) . tag ( tag . to_owned ( ) ) ) ; add_content ( file , content , tag_result ) }
Adds user provided content to a diary entry.
Adds user provided content to a diary entry .
opts
&AddOptions
diary
&Diary
date
&Date<Local>
string_getter
editing::StringGetter
The unit if adding the content was successful, a DiaryError otherwise.
The unit if adding the content was successful a DiaryError otherwise .
opts
&AddOptions
diary
&Diary
date
&Date<Local>
string_getter
editing::StringGetter