sqlx_exasol_impl/options/
compression.rs

1use std::str::FromStr;
2
3use super::{error::ExaConfigError, COMPRESSION};
4
5/// Options for controlling the desired compression behavior of the connection to the Exasol server.
6///
7/// It is used by [`crate::options::builder::ExaConnectOptionsBuilder::compression_mode`].
8#[derive(Debug, Clone, Copy, Default, PartialEq)]
9pub enum ExaCompressionMode {
10    /// Establish an uncompressed connection.
11    Disabled,
12
13    /// Establish a compressed connection if the compression feature is enabled, falling back to an
14    /// uncompressed connection if it's not.
15    ///
16    /// This is the default if `compression` is not specified.
17    #[default]
18    Preferred,
19
20    /// Establish a compressed connection if the compression feature is enabled.
21    /// The connection attempt fails if a compressed connection cannot be established.
22    Required,
23}
24
25impl ExaCompressionMode {
26    const DISABLED: &str = "disabled";
27    const PREFERRED: &str = "preferred";
28    const REQUIRED: &str = "required";
29}
30
31impl FromStr for ExaCompressionMode {
32    type Err = ExaConfigError;
33
34    fn from_str(s: &str) -> Result<Self, ExaConfigError> {
35        Ok(match &*s.to_ascii_lowercase() {
36            Self::DISABLED => ExaCompressionMode::Disabled,
37            Self::PREFERRED => ExaCompressionMode::Preferred,
38            Self::REQUIRED => ExaCompressionMode::Required,
39            _ => Err(ExaConfigError::InvalidParameter(COMPRESSION))?,
40        })
41    }
42}
43
44impl AsRef<str> for ExaCompressionMode {
45    fn as_ref(&self) -> &str {
46        match self {
47            ExaCompressionMode::Disabled => Self::DISABLED,
48            ExaCompressionMode::Preferred => Self::PREFERRED,
49            ExaCompressionMode::Required => Self::REQUIRED,
50        }
51    }
52}