Skip to content

Commit 476ea94

Browse files
authored
feat: Mark various functions as const (#674)
* Mark various functions as const * Update changelog
1 parent 76319b0 commit 476ea94

File tree

10 files changed

+34
-14
lines changed

10 files changed

+34
-14
lines changed

CHANGELOG.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,26 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Mark the following functions as `const` ([#674]):
10+
- `ClusterResourceApplyStrategy::delete_orphans`
11+
- `LdapAuthenticationProvider::default_port`
12+
- `LdapAuthenticationProvider::use_tls`
13+
- `ListenerSpec::default_publish_not_ready_addresses`
14+
- `OpaApiVersion::get_data_api`
15+
- `CpuQuantity::from_millis`
16+
- `CpuQuantity::as_milli_cpus`
17+
- `BinaryMultiple::exponential_scale_factor`
18+
- `BinaryMultiple::get_smallest`
19+
- `MemoryQuantity::from_gibi`
20+
- `MemoryQuantity::from_mebi`
21+
- `ClusterCondition::is_good`
22+
- `ClusterOperationsConditionBuilder::new`
23+
- `commons::pdb::default_pdb_enabled`
24+
25+
[#674]: https://github.com/stackabletech/operator-rs/pull/674
26+
727
### Changed
828

929
- Convert the format of the Vector configuration from TOML to YAML ([#670]).

src/cluster_resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl ClusterResourceApplyStrategy {
149149
}
150150

151151
/// Indicates if orphaned resources should be deleted depending on the strategy.
152-
fn delete_orphans(&self) -> bool {
152+
const fn delete_orphans(&self) -> bool {
153153
match self {
154154
ClusterResourceApplyStrategy::NoApply
155155
| ClusterResourceApplyStrategy::ReconciliationPaused => false,

src/commons/authentication/ldap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct LdapAuthenticationProvider {
3131
}
3232

3333
impl LdapAuthenticationProvider {
34-
pub fn default_port(&self) -> u16 {
34+
pub const fn default_port(&self) -> u16 {
3535
match self.tls {
3636
None => 389,
3737
Some(_) => 636,
@@ -91,7 +91,7 @@ impl LdapAuthenticationProvider {
9191
}
9292

9393
/// Whether TLS is configured
94-
pub fn use_tls(&self) -> bool {
94+
pub const fn use_tls(&self) -> bool {
9595
self.tls.is_some()
9696
}
9797

src/commons/listener.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ pub struct ListenerSpec {
9696
}
9797

9898
impl ListenerSpec {
99-
fn default_publish_not_ready_addresses() -> Option<bool> {
99+
const fn default_publish_not_ready_addresses() -> Option<bool> {
100100
Some(true)
101101
}
102102
}

src/commons/opa.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub enum OpaApiVersion {
6666

6767
impl OpaApiVersion {
6868
/// Returns the OPA data API path for the selected version
69-
pub fn get_data_api(&self) -> &'static str {
69+
pub const fn get_data_api(&self) -> &'static str {
7070
match self {
7171
Self::V1 => "v1/data",
7272
}

src/commons/pdb.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pub struct PdbConfig {
2020
pub max_unavailable: Option<u16>,
2121
}
2222

23-
fn default_pdb_enabled() -> bool {
23+
const fn default_pdb_enabled() -> bool {
2424
true
2525
}
2626

src/cpu.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ pub struct CpuQuantity {
2020
}
2121

2222
impl CpuQuantity {
23-
pub fn from_millis(millis: usize) -> Self {
23+
pub const fn from_millis(millis: usize) -> Self {
2424
Self { millis }
2525
}
2626

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

31-
pub fn as_milli_cpus(&self) -> usize {
31+
pub const fn as_milli_cpus(&self) -> usize {
3232
self.millis
3333
}
3434
}

src/memory.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ impl BinaryMultiple {
4242

4343
/// The exponential scale factor used when converting a `BinaryMultiple`
4444
/// to another one.
45-
fn exponential_scale_factor(&self) -> i32 {
45+
const fn exponential_scale_factor(&self) -> i32 {
4646
match self {
4747
BinaryMultiple::Kibi => 1,
4848
BinaryMultiple::Mebi => 2,
@@ -53,7 +53,7 @@ impl BinaryMultiple {
5353
}
5454
}
5555

56-
pub fn get_smallest() -> Self {
56+
pub const fn get_smallest() -> Self {
5757
Self::Kibi
5858
}
5959
}
@@ -160,14 +160,14 @@ pub struct MemoryQuantity {
160160
}
161161

162162
impl MemoryQuantity {
163-
pub fn from_gibi(gibi: f32) -> Self {
163+
pub const fn from_gibi(gibi: f32) -> Self {
164164
Self {
165165
value: gibi,
166166
unit: BinaryMultiple::Gibi,
167167
}
168168
}
169169

170-
pub fn from_mebi(mebi: f32) -> Self {
170+
pub const fn from_mebi(mebi: f32) -> Self {
171171
Self {
172172
value: mebi,
173173
unit: BinaryMultiple::Mebi,

src/status/condition/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ impl std::fmt::Display for ClusterCondition {
145145
impl ClusterCondition {
146146
/// Returns if the [`ClusterCondition`] is considered to be in a good /
147147
/// healthy state.
148-
pub fn is_good(&self) -> bool {
148+
pub const fn is_good(&self) -> bool {
149149
match self.type_ {
150150
ClusterConditionType::Available => match self.status {
151151
ClusterConditionStatus::False | ClusterConditionStatus::Unknown => false,

src/status/condition/operations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<'a> ConditionBuilder for ClusterOperationsConditionBuilder<'a> {
1818
}
1919

2020
impl<'a> ClusterOperationsConditionBuilder<'a> {
21-
pub fn new(cluster_operation: &'a ClusterOperation) -> Self {
21+
pub const fn new(cluster_operation: &'a ClusterOperation) -> Self {
2222
Self { cluster_operation }
2323
}
2424

0 commit comments

Comments
 (0)