Skip to content

feat: Mark various functions as const #674

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]).
Expand Down
2 changes: 1 addition & 1 deletion src/cluster_resources.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions src/commons/authentication/ldap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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()
}

Expand Down
2 changes: 1 addition & 1 deletion src/commons/listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub struct ListenerSpec {
}

impl ListenerSpec {
fn default_publish_not_ready_addresses() -> Option<bool> {
const fn default_publish_not_ready_addresses() -> Option<bool> {
Some(true)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/commons/opa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
Expand Down
2 changes: 1 addition & 1 deletion src/commons/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct PdbConfig {
pub max_unavailable: Option<u16>,
}

fn default_pdb_enabled() -> bool {
const fn default_pdb_enabled() -> bool {
true
}

Expand Down
4 changes: 2 additions & 2 deletions src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ pub struct CpuQuantity {
}

impl CpuQuantity {
pub fn from_millis(millis: usize) -> Self {
pub const fn from_millis(millis: usize) -> Self {
Self { millis }
}

pub fn as_cpu_count(&self) -> f32 {
self.millis as f32 / 1000.
}

pub fn as_milli_cpus(&self) -> usize {
pub const fn as_milli_cpus(&self) -> usize {
self.millis
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -53,7 +53,7 @@ impl BinaryMultiple {
}
}

pub fn get_smallest() -> Self {
pub const fn get_smallest() -> Self {
Self::Kibi
}
}
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/status/condition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/status/condition/operations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down