From 7bf8a7691d5fbb637da822a1172356c39ce3c4e9 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 8 Jan 2025 14:58:20 +0100 Subject: [PATCH 1/2] ref(api): Replace custom deserializer with derive This custom deserializer can be easily replaced with `derive(Deserialize)`. --- src/api/data_types/chunking/compression.rs | 26 ++++++---------------- 1 file changed, 7 insertions(+), 19 deletions(-) diff --git a/src/api/data_types/chunking/compression.rs b/src/api/data_types/chunking/compression.rs index 7bb1a1eadb..6c0660c802 100644 --- a/src/api/data_types/chunking/compression.rs +++ b/src/api/data_types/chunking/compression.rs @@ -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 { @@ -32,17 +34,3 @@ impl fmt::Display for ChunkCompression { } } } - -impl<'de> Deserialize<'de> for ChunkCompression { - fn deserialize(deserializer: D) -> Result - 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, - }) - } -} From a8e56799e79eef073a7d4ad022d398ed04be8a32 Mon Sep 17 00:00:00 2001 From: Daniel Szoke Date: Wed, 8 Jan 2025 15:04:36 +0100 Subject: [PATCH 2/2] ref(api): Move `compression` submodule A future change will add non-data-type-related logic to the `compression` submodule. It therefore makes sense to move the submodule directly under the `api` module. --- src/api/{data_types/chunking => }/compression.rs | 0 src/api/data_types/chunking/mod.rs | 3 +-- src/api/mod.rs | 2 ++ 3 files changed, 3 insertions(+), 2 deletions(-) rename src/api/{data_types/chunking => }/compression.rs (100%) diff --git a/src/api/data_types/chunking/compression.rs b/src/api/compression.rs similarity index 100% rename from src/api/data_types/chunking/compression.rs rename to src/api/compression.rs diff --git a/src/api/data_types/chunking/mod.rs b/src/api/data_types/chunking/mod.rs index 0af308c87c..9ac0ba7f63 100644 --- a/src/api/data_types/chunking/mod.rs +++ b/src/api/data_types/chunking/mod.rs @@ -2,15 +2,14 @@ //! from the server. mod artifact; -mod compression; mod dif; mod file_state; mod hash_algorithm; mod upload; pub use self::artifact::{AssembleArtifactsResponse, ChunkedArtifactRequest}; -pub use self::compression::ChunkCompression; pub use self::dif::{AssembleDifsRequest, AssembleDifsResponse, ChunkedDifRequest}; pub use self::file_state::ChunkedFileState; pub use self::hash_algorithm::ChunkHashAlgorithm; pub use self::upload::{ChunkServerOptions, ChunkUploadCapability}; +use crate::api::ChunkCompression; diff --git a/src/api/mod.rs b/src/api/mod.rs index ab1cd5ad10..86d2bdcdf7 100644 --- a/src/api/mod.rs +++ b/src/api/mod.rs @@ -5,6 +5,7 @@ pub mod envelopes_api; +mod compression; mod connection_manager; mod data_types; mod encoding; @@ -54,6 +55,7 @@ use crate::utils::retry::{get_default_backoff, DurationAsMilliseconds}; use crate::utils::sourcemaps::get_sourcemap_reference_from_headers; use crate::utils::ui::{capitalize_string, make_byte_progress_bar}; +use self::compression::ChunkCompression; use self::pagination::Pagination; use connection_manager::CurlConnectionManager; use encoding::{PathArg, QueryArg};