Skip to content

Commit

Permalink
ref(api): Replace custom deserializer with derive (#2337)
Browse files Browse the repository at this point in the history
This custom deserializer can be easily replaced with
`derive(Deserialize)`.
  • Loading branch information
szokeasaurusrex authored Jan 17, 2025
1 parent ee953a5 commit 6e188bf
Showing 1 changed file with 7 additions and 19 deletions.
26 changes: 7 additions & 19 deletions src/api/data_types/chunking/compression.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
use std::fmt;

use serde::{Deserialize, Deserializer};
use serde::Deserialize;

#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Default)]
#[derive(Debug, Clone, Copy, Ord, PartialOrd, Eq, PartialEq, Default, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ChunkCompression {
/// No compression should be applied
#[default]
Uncompressed = 0,
/// GZIP compression (including header)
Gzip = 10,
/// Brotli compression
Brotli = 20,
/// No compression should be applied
#[default]
#[serde(other)]
Uncompressed = 0,
}

impl ChunkCompression {
Expand All @@ -32,17 +34,3 @@ impl fmt::Display for ChunkCompression {
}
}
}

impl<'de> Deserialize<'de> for ChunkCompression {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
Ok(match String::deserialize(deserializer)?.as_str() {
"gzip" => ChunkCompression::Gzip,
"brotli" => ChunkCompression::Brotli,
// We do not know this compression, so we assume no compression
_ => ChunkCompression::Uncompressed,
})
}
}

0 comments on commit 6e188bf

Please sign in to comment.