pub fn new(
    opts: &NewOptions,
    diary: &Diary,
    date: &Date<Local>,
    string_getter: editing::StringGetter,
) -> Result<(), DiaryError> {
    let mut new_entry_path = file_system::month_folder(diary.diary_path(), date);
    file_system::create_month_folder(&new_entry_path)?;

    let entry_name = diary.file_name(date);

    new_entry_path.push(entry_name);
    let result = OpenOptions::new()
        .write(true)
        .create_new(true)
        .open(new_entry_path);

    let mut file = match result {
        Ok(mut file) => {
            editing::add_user_content_to_file(&mut file, diary.file_type().title(date))?;
            file
        }
        Err(e) => return Err(e.into()),
    };
    if opts.open {
        let contents = string_getter("".to_owned())?;
        editing::add_user_content_to_file(&mut file, contents)?;
    };
    Ok(())
}
/// Creates a new diary entry.
///
/// # Arguments
///
/// * `opts` - The options passed by the user at runtime.
/// * `diary` - Struct representing the diary.
/// * `date` - The date for which to create the new entry.
/// * `string_getter` - The function that obtains the string to add to the file.
///
/// # Returns
///
/// The unit upon successful creation of the entry.
/// DiaryError if the entry already exists.
/// DiaryError on any other IO issues.
Creates a new diary entry.
Creates a new diary entry .
pub fn new(
    opts: &NewOptions,
    diary: &Diary,
    date: &Date<Local>,
    string_getter: editing::StringGetter,
) -> Result<(), DiaryError> {
    let mut new_entry_path = file_system::month_folder(diary.diary_path(), date);
    file_system::create_month_folder(&new_entry_path)?;
    let entry_name = diary.file_name(date);
    new_entry_path.push(entry_name);
    let result = OpenOptions::new()
        .write(true)
        .create_new(true)
        .open(new_entry_path);
    let mut file = match result {
        Ok(mut file) => {
            editing::add_user_content_to_file(&mut file, diary.file_type().title(date))?;
            file
        }
        Err(e) => return Err(e.into()),
    };
    if opts.open {
        let contents = string_getter("".to_owned())?;
        editing::add_user_content_to_file(&mut file, contents)?;
    };
    Ok(())
}
pub fn new ( opts : & NewOptions , diary : & Diary , date : & Date < Local > , string_getter : editing :: StringGetter , ) -> Result < ( ) , DiaryError > { let mut new_entry_path = file_system :: month_folder ( diary . diary_path ( ) , date ) ; file_system :: create_month_folder ( & new_entry_path ) ? ; let entry_name = diary . file_name ( date ) ; new_entry_path . push ( entry_name ) ; let result = OpenOptions :: new ( ) . write ( true ) . create_new ( true ) . open ( new_entry_path ) ; let mut file = match result { Ok ( mut file ) => { editing :: add_user_content_to_file ( & mut file , diary . file_type ( ) . title ( date ) ) ? ; file } Err ( e ) => return Err ( e . into ( ) ) , } ; if opts . open { let contents = string_getter ( " " . to_owned ( ) ) ? ; editing :: add_user_content_to_file ( & mut file , contents ) ? ; } ; Ok ( ( ) ) }
Creates a new diary entry.
Creates a new diary entry .
opts
&NewOptions
diary
&Diary
date
&Date<Local>
string_getter
editing::StringGetter
The unit upon successful creation of the entry.
DiaryError if the entry already exists.
DiaryError on any other IO issues.
The unit upon successful creation of the entry . DiaryError if the entry already exists . DiaryError on any other IO issues .
opts
&NewOptions
diary
&Diary
date
&Date<Local>
string_getter
editing::StringGetter