fn read_activities(file_path: &Path) -> ActivitiesOrError {
    let contents = match fs::read_to_string(file_path) {
        Ok(raw) => raw,
        Err(error) => match error.kind() {
            std::io::ErrorKind::NotFound => return Ok(Vec::new()),
            _ => bail!(error),
        },
    };

    let mut activities = Vec::new();

    let mut lines = contents.lines();
    if let Some(preamble) = lines.next() {
        if preamble.trim() != PREAMBLE_ACTIVITIES_V1 {
            bail!(ParseError::new(
                "No valid preamble found - unable to determine file format",
            ));
        }
    } else {
        bail!(ParseError::new("File seems to be empty"));
    }

    for line in lines {
        let line = line.trim();
        if line.starts_with('#') || line.is_empty() {
            continue;
        }

        match parse_activity(line) {
            Ok(activity) => activities.push(activity),
            Err(error) => eprintln!(
                "Skipping unreadable activity <{}> in {}: {:?}",
                line,
                file_path.to_str().unwrap(),
                error
            ),
        }
    }

    Ok(activities)
}
/// Read all activities in the given file. If the file does not exist an empty list is returned.
Read all activities in the given file. If the file does not exist an empty list is returned.
Read all activities in the given file . If the file does not exist an empty list is returned .
fn read_activities(file_path: &Path) -> ActivitiesOrError {
    let contents = match fs::read_to_string(file_path) {
        Ok(raw) => raw,
        Err(error) => match error.kind() {
            std::io::ErrorKind::NotFound => return Ok(Vec::new()),
            _ => bail!(error),
        },
    };
    let mut activities = Vec::new();
    let mut lines = contents.lines();
    if let Some(preamble) = lines.next() {
        if preamble.trim() != PREAMBLE_ACTIVITIES_V1 {
            bail!(ParseError::new(
                "No valid preamble found - unable to determine file format",
            ));
        }
    } else {
        bail!(ParseError::new("File seems to be empty"));
    }
    for line in lines {
        let line = line.trim();
        if line.starts_with('#') || line.is_empty() {
            continue;
        }
        match parse_activity(line) {
            Ok(activity) => activities.push(activity),
            Err(error) => eprintln!(
                "Skipping unreadable activity <{}> in {}: {:?}",
                line,
                file_path.to_str().unwrap(),
                error
            ),
        }
    }
    Ok(activities)
}
fn read_activities ( file_path : & Path ) -> ActivitiesOrError { let contents = match fs :: read_to_string ( file_path ) { Ok ( raw ) => raw , Err ( error ) => match error . kind ( ) { std :: io :: ErrorKind :: NotFound => return Ok ( Vec :: new ( ) ) , _ => bail ! ( error ) , } , } ; let mut activities = Vec :: new ( ) ; let mut lines = contents . lines ( ) ; if let Some ( preamble ) = lines . next ( ) { if preamble . trim ( ) != PREAMBLE_ACTIVITIES_V1 { bail ! ( ParseError new ( " " ) ) ; } } else { bail ! ( ParseError new ( " " ) ) ; } for line in lines { let line = line . trim ( ) ; if line . starts_with ( '#' ) || line . is_empty ( ) { continue ; } match parse_activity ( line ) { Ok ( activity ) => activities . push ( activity ) , Err ( error ) => eprintln ! ( " " line file_path to_str ( ) unwrap ( ) error ) , } } Ok ( activities ) }
Read all activities in the given file.
Read all activities in the given file .
file_path
&Path