From 05a41a45bb6f1e001dbcf77c4b95a0990e4c0ee6 Mon Sep 17 00:00:00 2001 From: Techassi Date: Thu, 12 Oct 2023 15:49:03 +0200 Subject: [PATCH 1/2] Mark various functions as const --- src/cluster_resources.rs | 2 +- src/commons/authentication/ldap.rs | 4 ++-- src/commons/listener.rs | 2 +- src/commons/opa.rs | 2 +- src/commons/pdb.rs | 2 +- src/cpu.rs | 4 ++-- src/memory.rs | 8 ++++---- src/status/condition/mod.rs | 2 +- src/status/condition/operations.rs | 2 +- 9 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/cluster_resources.rs b/src/cluster_resources.rs index af1001341..0e986fdeb 100644 --- a/src/cluster_resources.rs +++ b/src/cluster_resources.rs @@ -149,7 +149,7 @@ impl ClusterResourceApplyStrategy { } /// Indicates if orphaned resources should be deleted depending on the strategy. - fn delete_orphans(&self) -> bool { + const fn delete_orphans(&self) -> bool { match self { ClusterResourceApplyStrategy::NoApply | ClusterResourceApplyStrategy::ReconciliationPaused => false, diff --git a/src/commons/authentication/ldap.rs b/src/commons/authentication/ldap.rs index 2783cac70..a15da7207 100644 --- a/src/commons/authentication/ldap.rs +++ b/src/commons/authentication/ldap.rs @@ -31,7 +31,7 @@ pub struct LdapAuthenticationProvider { } impl LdapAuthenticationProvider { - pub fn default_port(&self) -> u16 { + pub const fn default_port(&self) -> u16 { match self.tls { None => 389, Some(_) => 636, @@ -91,7 +91,7 @@ impl LdapAuthenticationProvider { } /// Whether TLS is configured - pub fn use_tls(&self) -> bool { + pub const fn use_tls(&self) -> bool { self.tls.is_some() } diff --git a/src/commons/listener.rs b/src/commons/listener.rs index 24f79472f..ac69aa8a8 100644 --- a/src/commons/listener.rs +++ b/src/commons/listener.rs @@ -96,7 +96,7 @@ pub struct ListenerSpec { } impl ListenerSpec { - fn default_publish_not_ready_addresses() -> Option { + const fn default_publish_not_ready_addresses() -> Option { Some(true) } } diff --git a/src/commons/opa.rs b/src/commons/opa.rs index 80890abb9..d5557e6c8 100644 --- a/src/commons/opa.rs +++ b/src/commons/opa.rs @@ -66,7 +66,7 @@ pub enum OpaApiVersion { impl OpaApiVersion { /// Returns the OPA data API path for the selected version - pub fn get_data_api(&self) -> &'static str { + pub const fn get_data_api(&self) -> &'static str { match self { Self::V1 => "v1/data", } diff --git a/src/commons/pdb.rs b/src/commons/pdb.rs index 995af8102..9211d5391 100644 --- a/src/commons/pdb.rs +++ b/src/commons/pdb.rs @@ -20,7 +20,7 @@ pub struct PdbConfig { pub max_unavailable: Option, } -fn default_pdb_enabled() -> bool { +const fn default_pdb_enabled() -> bool { true } diff --git a/src/cpu.rs b/src/cpu.rs index 005d32e5b..422810b87 100644 --- a/src/cpu.rs +++ b/src/cpu.rs @@ -20,7 +20,7 @@ pub struct CpuQuantity { } impl CpuQuantity { - pub fn from_millis(millis: usize) -> Self { + pub const fn from_millis(millis: usize) -> Self { Self { millis } } @@ -28,7 +28,7 @@ impl CpuQuantity { self.millis as f32 / 1000. } - pub fn as_milli_cpus(&self) -> usize { + pub const fn as_milli_cpus(&self) -> usize { self.millis } } diff --git a/src/memory.rs b/src/memory.rs index b16a6248c..7a357f72a 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -42,7 +42,7 @@ impl BinaryMultiple { /// The exponential scale factor used when converting a `BinaryMultiple` /// to another one. - fn exponential_scale_factor(&self) -> i32 { + const fn exponential_scale_factor(&self) -> i32 { match self { BinaryMultiple::Kibi => 1, BinaryMultiple::Mebi => 2, @@ -53,7 +53,7 @@ impl BinaryMultiple { } } - pub fn get_smallest() -> Self { + pub const fn get_smallest() -> Self { Self::Kibi } } @@ -160,14 +160,14 @@ pub struct MemoryQuantity { } impl MemoryQuantity { - pub fn from_gibi(gibi: f32) -> Self { + pub const fn from_gibi(gibi: f32) -> Self { Self { value: gibi, unit: BinaryMultiple::Gibi, } } - pub fn from_mebi(mebi: f32) -> Self { + pub const fn from_mebi(mebi: f32) -> Self { Self { value: mebi, unit: BinaryMultiple::Mebi, diff --git a/src/status/condition/mod.rs b/src/status/condition/mod.rs index 2cf473f2d..026686312 100644 --- a/src/status/condition/mod.rs +++ b/src/status/condition/mod.rs @@ -145,7 +145,7 @@ impl std::fmt::Display for ClusterCondition { impl ClusterCondition { /// Returns if the [`ClusterCondition`] is considered to be in a good / /// healthy state. - pub fn is_good(&self) -> bool { + pub const fn is_good(&self) -> bool { match self.type_ { ClusterConditionType::Available => match self.status { ClusterConditionStatus::False | ClusterConditionStatus::Unknown => false, diff --git a/src/status/condition/operations.rs b/src/status/condition/operations.rs index d0e3c36ba..55d747fbf 100644 --- a/src/status/condition/operations.rs +++ b/src/status/condition/operations.rs @@ -18,7 +18,7 @@ impl<'a> ConditionBuilder for ClusterOperationsConditionBuilder<'a> { } impl<'a> ClusterOperationsConditionBuilder<'a> { - pub fn new(cluster_operation: &'a ClusterOperation) -> Self { + pub const fn new(cluster_operation: &'a ClusterOperation) -> Self { Self { cluster_operation } } From a0f92d99b7b2b16d957c4d771fe164a8521aada2 Mon Sep 17 00:00:00 2001 From: Techassi Date: Thu, 12 Oct 2023 16:30:33 +0200 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d087bff42..ca8da40e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Added + +- Mark the following functions as `const` ([#674]): + - `ClusterResourceApplyStrategy::delete_orphans` + - `LdapAuthenticationProvider::default_port` + - `LdapAuthenticationProvider::use_tls` + - `ListenerSpec::default_publish_not_ready_addresses` + - `OpaApiVersion::get_data_api` + - `CpuQuantity::from_millis` + - `CpuQuantity::as_milli_cpus` + - `BinaryMultiple::exponential_scale_factor` + - `BinaryMultiple::get_smallest` + - `MemoryQuantity::from_gibi` + - `MemoryQuantity::from_mebi` + - `ClusterCondition::is_good` + - `ClusterOperationsConditionBuilder::new` + - `commons::pdb::default_pdb_enabled` + +[#674]: https://github.com/stackabletech/operator-rs/pull/674 + ### Changed - Convert the format of the Vector configuration from TOML to YAML ([#670]).