Make Column a strum

This commit is contained in:
RumovZ 2021-04-06 16:54:09 +02:00
parent 08226e2004
commit 929b7dc15b

View file

@ -5,6 +5,7 @@ use std::sync::Arc;
use itertools::Itertools; use itertools::Itertools;
use serde_repr::{Deserialize_repr, Serialize_repr}; use serde_repr::{Deserialize_repr, Serialize_repr};
use strum::{Display, EnumString};
use crate::error::{AnkiError, Result}; use crate::error::{AnkiError, Result};
use crate::i18n::I18n; use crate::i18n::I18n;
@ -21,9 +22,11 @@ use crate::{
timestamp::{TimestampMillis, TimestampSecs}, timestamp::{TimestampMillis, TimestampSecs},
}; };
#[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Clone, Copy)] #[derive(Serialize_repr, Deserialize_repr, Debug, PartialEq, Clone, Copy, Display, EnumString)]
#[strum(serialize_all = "camelCase")]
#[repr(u8)] #[repr(u8)]
pub enum Column { pub enum Column {
#[strum(serialize = "")]
Custom, Custom,
Question, Question,
Answer, Answer,
@ -31,23 +34,35 @@ pub enum Column {
CardDue, CardDue,
CardEase, CardEase,
CardLapses, CardLapses,
#[strum(serialize = "cardIvl")]
CardInterval, CardInterval,
CardMod, CardMod,
CardReps, CardReps,
#[strum(serialize = "template")]
CardTemplate, CardTemplate,
NoteCards, NoteCards,
#[strum(serialize = "noteCrt")]
NoteCreation, NoteCreation,
NoteDue, NoteDue,
NoteEase, NoteEase,
#[strum(serialize = "noteFld")]
NoteField, NoteField,
#[strum(serialize = "noteIvl")]
NoteInterval, NoteInterval,
NoteLapses, NoteLapses,
NoteMod, NoteMod,
NoteReps, NoteReps,
NoteTags, NoteTags,
#[strum(serialize = "note")]
Notetype, Notetype,
} }
impl Default for Column {
fn default() -> Self {
Column::Custom
}
}
#[derive(Debug, PartialEq)] #[derive(Debug, PartialEq)]
pub struct Row { pub struct Row {
pub cells: Vec<Cell>, pub cells: Vec<Cell>,