use strum package to simplify PragmaName enum management

The pragma list will only grow. The strum crate can be used to:
* automatically convert to string from enum
* automatically convert to enum from string
* implement an iterator over all elements of the enum
This commit is contained in:
Glauber Costa
2025-01-30 20:42:41 -05:00
parent e96b649a1a
commit 62efbde661
3 changed files with 7 additions and 16 deletions

View File

@@ -7,6 +7,8 @@ use std::num::ParseIntError;
use std::ops::Deref;
use std::str::{self, Bytes, FromStr};
use strum_macros::{EnumIter, EnumString};
use fmt::{ToTokens, TokenStream};
use indexmap::{IndexMap, IndexSet};
@@ -1585,7 +1587,8 @@ pub type PragmaValue = Expr; // TODO
/// `PRAGMA` value
// https://sqlite.org/pragma.html
#[derive(Clone, Debug, PartialEq, Eq)]
#[derive(Clone, Debug, PartialEq, Eq, EnumIter, EnumString, strum::Display)]
#[strum(serialize_all = "snake_case")]
pub enum PragmaName {
/// `cache_size` pragma
CacheSize,
@@ -1597,20 +1600,6 @@ pub enum PragmaName {
TableInfo,
}
impl FromStr for PragmaName {
type Err = ();
fn from_str(input: &str) -> Result<Self, Self::Err> {
match input {
"cache_size" => Ok(PragmaName::CacheSize),
"wal_checkpoint" => Ok(PragmaName::WalCheckpoint),
"journal_mode" => Ok(PragmaName::JournalMode),
"table_info" => Ok(PragmaName::TableInfo),
_ => Err(()),
}
}
}
/// `CREATE TRIGGER` time
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum TriggerTime {