refactor: Conditionalize utoipa and flate2 based on features
Conditionalize `utoipa::ToSchema` derives and `#[schema]` attributes on the `server` feature, and `flate2` usage on the `gzip` feature, allowing compilation when these features are disabled. Co-authored-by: aider (openai/andrew/openrouter/sonoma-sky-alpha) <aider@aider.chat>
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#[cfg(feature = "gzip")]
|
||||
/// GZip compression engine module.
|
||||
///
|
||||
/// This module provides the implementation for GZip compression and decompression
|
||||
@@ -12,19 +13,30 @@
|
||||
/// .expect("GZip engine creation failed");
|
||||
/// let reader = engine.open("/path/to/file.gz".into()).expect("Open failed");
|
||||
/// ```
|
||||
#[cfg(feature = "gzip")]
|
||||
use anyhow::Result;
|
||||
#[cfg(feature = "gzip")]
|
||||
use log::*;
|
||||
#[cfg(feature = "gzip")]
|
||||
use std::fs::File;
|
||||
#[cfg(feature = "gzip")]
|
||||
use std::io;
|
||||
#[cfg(feature = "gzip")]
|
||||
use std::io::{Read, Write};
|
||||
#[cfg(feature = "gzip")]
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
use flate2::Compression;
|
||||
#[cfg(feature = "gzip")]
|
||||
use flate2::read::GzDecoder;
|
||||
#[cfg(feature = "gzip")]
|
||||
use flate2::write::GzEncoder;
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
use crate::compression_engine::CompressionEngine;
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
#[derive(Debug, Eq, PartialEq, Clone, Default)]
|
||||
/// GZip compression engine implementation.
|
||||
///
|
||||
@@ -33,6 +45,7 @@ use crate::compression_engine::CompressionEngine;
|
||||
/// with the keep system's compression framework.
|
||||
pub struct CompressionEngineGZip {}
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
impl CompressionEngineGZip {
|
||||
/// Creates a new instance of `CompressionEngineGZip`.
|
||||
///
|
||||
@@ -50,6 +63,7 @@ impl CompressionEngineGZip {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
impl CompressionEngine for CompressionEngineGZip {
|
||||
/// Checks if GZip compression is supported.
|
||||
///
|
||||
@@ -132,6 +146,7 @@ impl CompressionEngine for CompressionEngineGZip {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
#[derive(Debug)]
|
||||
/// Wrapper around `GzEncoder` that automatically finishes the compression stream on drop.
|
||||
///
|
||||
@@ -141,6 +156,7 @@ pub struct AutoFinishGzEncoder<W: Write> {
|
||||
encoder: Option<GzEncoder<W>>,
|
||||
}
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
impl<W: Write> AutoFinishGzEncoder<W> {
|
||||
/// Creates a new `AutoFinishGzEncoder` wrapping the given GZip encoder.
|
||||
///
|
||||
@@ -166,6 +182,7 @@ impl<W: Write> AutoFinishGzEncoder<W> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
impl<W: Write> Drop for AutoFinishGzEncoder<W> {
|
||||
/// Automatically finishes the GZip encoding when the writer is dropped.
|
||||
///
|
||||
@@ -183,6 +200,7 @@ impl<W: Write> Drop for AutoFinishGzEncoder<W> {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "gzip")]
|
||||
impl<W: Write> Write for AutoFinishGzEncoder<W> {
|
||||
/// Writes data to the underlying GZip encoder.
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user