From 0548acfd4d6795d2801b71cc7b57c8b18373c8ac Mon Sep 17 00:00:00 2001 From: Thibault Martinez Date: Thu, 18 Nov 2021 07:57:25 +0100 Subject: [PATCH] Derive `serde::{Serialize, Deserialize}` for configuration enums (#556) --- Cargo.toml | 2 ++ src/db_options.rs | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d9a0b82..07c02a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,10 +27,12 @@ zlib = ["librocksdb-sys/zlib"] bzip2 = ["librocksdb-sys/bzip2"] rtti = ["librocksdb-sys/rtti"] multi-threaded-cf = [] +serde1 = ["serde"] [dependencies] libc = "0.2" librocksdb-sys = { path = "librocksdb-sys", version = "6.20.3" } +serde = { version = "1", features = [ "derive" ], optional = true } [dev-dependencies] trybuild = "1.0" diff --git a/src/db_options.rs b/src/db_options.rs index bdb92a0..09f0f91 100644 --- a/src/db_options.rs +++ b/src/db_options.rs @@ -3085,6 +3085,7 @@ impl Default for WriteOptions { } #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] #[repr(i32)] pub enum ReadTier { /// Reads data in memtable, block cache, OS cache or storage. @@ -3409,6 +3410,7 @@ pub struct PlainTableFactoryOptions { } #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub enum DBCompressionType { None = ffi::rocksdb_no_compression as isize, Snappy = ffi::rocksdb_snappy_compression as isize, @@ -3420,6 +3422,7 @@ pub enum DBCompressionType { } #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub enum DBCompactionStyle { Level = ffi::rocksdb_level_compaction as isize, Universal = ffi::rocksdb_universal_compaction as isize, @@ -3427,6 +3430,7 @@ pub enum DBCompactionStyle { } #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub enum DBRecoveryMode { TolerateCorruptedTailRecords = ffi::rocksdb_tolerate_corrupted_tail_records_recovery as isize, AbsoluteConsistency = ffi::rocksdb_absolute_consistency_recovery as isize, @@ -3436,6 +3440,7 @@ pub enum DBRecoveryMode { /// File access pattern once a compaction has started #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] #[repr(i32)] pub enum AccessHint { None = 0, @@ -3481,6 +3486,7 @@ impl FifoCompactOptions { } #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] pub enum UniversalCompactionStopStyle { Similar = ffi::rocksdb_similar_size_compaction_stop_style as isize, Total = ffi::rocksdb_total_size_compaction_stop_style as isize, @@ -3594,6 +3600,7 @@ impl UniversalCompactOptions { } #[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde1", derive(serde::Serialize, serde::Deserialize))] #[repr(u8)] pub enum BottommostLevelCompaction { /// Skip bottommost level compaction