Ease enum doesn't handle value 0, causing deserialization error

When using anki_bridge with AnkiConnect, the library fails to deserialize review data when Anki returns an ease value of 0. This causes the following error:

Reqwest(reqwest::Error { kind: Decode, source: Error("unknown variant 0, expected one of 0, 1, 2, 3, 4", line: 1, column: 74) })

btw, an ease of 0 is for manually scheduled cards, see the discussion here https://forums.ankiweb.net/t/understanding-the-revlog-table/51197/3

this is very sneaky case and don't show up in the docs I can find online...

Cause

The Ease enum in src/entities/review.rs only handles values 1-4:

  • 1 = Again
  • 2 = Hard
  • 3 = Good
  • 4 = Easy

we can add a Manual = 0 variant to the Ease enum to handle this case:

pub enum Ease {
    #[default]
    Unknown = 0,
    Again = 1,
    Hard = 2,
    Good = 3,
    Easy = 4,
}

And update the deserializer to handle this case:

  match value {
      0 => Ok(Ease::Unknown),
      1 => Ok(Ease::Again),
      2 => Ok(Ease::Hard),
      3 => Ok(Ease::Good),
      4 => Ok(Ease::Easy),
      _ => Err(serde::de::Error::unknown_variant(
          value.to_string().as_str(),
          &["0", "1", "2", "3", "4"],
      )),
  }