Iced + Rusqlite + Chrono: Problem with custom error type

⚓ Rust    📅 2026-04-24    👤 surdeus    👁️ 1      

surdeus

I am trying to learn to better harness rusts functionality. In an attempt to do so I am using a custom error which will allow the use of ? to handle both chrono and rusqlite errors in the returned result from a function. The code compiles/runs and the correct string values are returned. But I get several warnings which I do not understand how to resolve. Below is the function and the warning messages. Any assistance will be appreciated.

#[derive(Debug)]
pub enum SqlChronoError  {
    SqlError(rusqlite::Error),
    ChronoError(chrono::ParseError),
}
impl From<rusqlite::Error> for SqlChronoError {
    fn from(error: rusqlite::Error) -> Self {
        SqlChronoError::SqlError(error)
    }
}
impl From<chrono::ParseError> for SqlChronoError {
    fn from(error: chrono::ParseError) -> Self {
        SqlChronoError::ChronoError(error)
    }
}

pub async fn get_start_dates() -> Result<Vec<String>, SqlChronoError> {

    let db_file_path: &str = "stock_data.db";
    let conn = Connection::open(db_file_path)?;

    let lastest_datetime_string = conn.query_row("SELECT MAX(date) FROM data", [], |row| row.get(0).map(|x: String| x.to_string()))?;
    let latest_datetime = NaiveDate::parse_from_str(&lastest_datetime_string, "%Y-%m-%d")?;

    const OFFSET_DAYS: [Days; 4] = [Days::new(90),
                                    Days::new(180),
                                    Days::new(365),
                                    Days::new(3650)];

    let start_dates = OFFSET_DAYS.iter()
            .filter_map(|offset| latest_datetime.checked_sub_days(*offset))
            .map(|nav_date| nav_date.format("%Y-%m-%d").to_string())
            .collect::<Vec<String>>();

    Ok(start_dates)
}


warning: field `0` is never read
 --> src/functions/start_dates.rs:6:14
  |
6 |     SqlError(rusqlite::Error),
  |     -------- ^^^^^^^^^^^^^^^
  |     |
  |     field in this variant
  |
  = note: `SqlChronoError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
  = note: `#[warn(dead_code)]` (part of `#[warn(unused)]`) on by default
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
6 -     SqlError(rusqlite::Error),
6 +     SqlError(()),
  |

warning: field `0` is never read
 --> src/functions/start_dates.rs:7:17
  |
7 |     ChronoError(chrono::ParseError),
  |     ----------- ^^^^^^^^^^^^^^^^^^
  |     |
  |     field in this variant
  |
  = note: `SqlChronoError` has a derived impl for the trait `Debug`, but this is intentionally ignored during dead code analysis
help: consider changing the field to be of unit type to suppress this warning while preserving the field numbering, or remove the field
  |
7 -     ChronoError(chrono::ParseError),
7 +     ChronoError(()),
  |

warning: `csvtosql` (bin "csvtosql") generated 2 warnings

2 posts - 2 participants

Read full topic

🏷️ Rust_feed