sdf-metadata 0.14.0

metadata definition for core sdf
Documentation
use crate::wit::io::ProducerConfig;

impl ProducerConfig {
    pub fn merge(&mut self, other: &ProducerConfig) {
        if self.linger_ms.is_none() {
            self.linger_ms = other.linger_ms;
        }
        if self.compression.is_none() {
            self.compression = other.compression;
        }

        if self.isolation.is_none() {
            self.isolation = other.isolation;
        }

        if self.timeout_ms.is_none() {
            self.timeout_ms = other.timeout_ms;
        }

        if self.batch_size_bytes.is_none() {
            self.batch_size_bytes = other.batch_size_bytes;
        }
    }
}

#[allow(clippy::derivable_impls)]
impl Default for ProducerConfig {
    fn default() -> Self {
        Self {
            linger_ms: None,
            batch_size_bytes: None,
            isolation: None,
            compression: None,
            timeout_ms: None,
        }
    }
}

#[cfg(test)]
mod test {
    use crate::wit::io::Compression;

    #[test]
    fn test_producer_config_merge() {
        let mut config1 = super::ProducerConfig {
            linger_ms: Some(100),
            compression: Some(Compression::Gzip),
            ..Default::default()
        };

        let config2 = super::ProducerConfig {
            linger_ms: Some(200),
            batch_size_bytes: Some(1024),
            isolation: Some(crate::wit::io::Isolation::ReadCommitted),
            timeout_ms: Some(500),
            ..Default::default()
        };

        config1.merge(&config2);

        assert_eq!(config1.linger_ms, Some(100));
        assert_eq!(config1.batch_size_bytes, Some(1024));
        assert_eq!(
            config1.isolation,
            Some(crate::wit::io::Isolation::ReadCommitted)
        );
        assert_eq!(config1.compression, Some(Compression::Gzip));
        assert_eq!(config1.timeout_ms, Some(500));
    }
}