pub fn read_data(path: Option<&str>, throw_generic: bool) -> Result<(String, String), DataError> {
    // just testing generic error type
    if throw_generic {
        let source_err = std::io::Error::new(std::io::ErrorKind::Other, "oh no! a generic source");
        return Err(DataError::SourceIsGeneric(Box::new(source_err)));
    }

    let file_path = match path {
        Some(p) => p.to_string(),
        None => {
            let value =
                read_config_file().map_err(|source| DataError::ReadConfigError { source })?;
            let default = value.get("default").ok_or(DataError::ConfigInfoNotFound)?;
            println!("Using default file path: {}", default);
            default.to_string()
        }
    };

    let value = read_data_file(&file_path).map_err(|source| DataError::ReadDataError { source })?;
    let name = value
        .get("name")
        .ok_or(DataError::ContactInfoNotFound("name".to_string()))?;

    let phones = value
        .get("phones")
        .ok_or(DataError::ContactInfoNotFound("phones".to_string()))?;

    Ok((name.to_string(), phones[0].to_string()))
}
// read name and phone number from file
read name and phone number from file
read name and phone number from file
pub fn read_data(path: Option<&str>, throw_generic: bool) -> Result<(String, String), DataError> {
    // just testing generic error type
    if throw_generic {
        let source_err = std::io::Error::new(std::io::ErrorKind::Other, "oh no! a generic source");
        return Err(DataError::SourceIsGeneric(Box::new(source_err)));
    }
    let file_path = match path {
        Some(p) => p.to_string(),
        None => {
            let value =
                read_config_file().map_err(|source| DataError::ReadConfigError { source })?;
            let default = value.get("default").ok_or(DataError::ConfigInfoNotFound)?;
            println!("Using default file path: {}", default);
            default.to_string()
        }
    };
    let value = read_data_file(&file_path).map_err(|source| DataError::ReadDataError { source })?;
    let name = value
        .get("name")
        .ok_or(DataError::ContactInfoNotFound("name".to_string()))?;
    let phones = value
        .get("phones")
        .ok_or(DataError::ContactInfoNotFound("phones".to_string()))?;
    Ok((name.to_string(), phones[0].to_string()))
}
pub fn read_data ( path : Option < & str > , throw_generic : bool ) -> Result < ( String , String ) , DataError > { // just testing generic error type if throw_generic { let source_err = std :: io :: Error :: new ( std :: io :: ErrorKind :: Other , " " ) ; return Err ( DataError :: SourceIsGeneric ( Box :: new ( source_err ) ) ) ; } let file_path = match path { Some ( p ) => p . to_string ( ) , None => { let value = read_config_file ( ) . map_err ( | source | DataError :: ReadConfigError { source } ) ? ; let default = value . get ( " " ) . ok_or ( DataError :: ConfigInfoNotFound ) ? ; println ! ( " " default ) ; default . to_string ( ) } } ; let value = read_data_file ( & file_path ) . map_err ( | source | DataError :: ReadDataError { source } ) ? ; let name = value . get ( " " ) . ok_or ( DataError :: ContactInfoNotFound ( " " . to_string ( ) ) ) ? ; let phones = value . get ( " " ) . ok_or ( DataError :: ContactInfoNotFound ( " " . to_string ( ) ) ) ? ; Ok ( ( name . to_string ( ) , phones [ 0 ] . to_string ( ) ) ) }
read name and phone number from file
read name and phone number from file
path
Option<&str>
throw_generic
bool
path
Option<&str>
throw_generic
bool