Skip to content

Commit 48ef413

Browse files
committed
refactor: Simplify From and Build trait usages
1 parent 951f5cc commit 48ef413

File tree

4 files changed

+33
-45
lines changed

4 files changed

+33
-45
lines changed

crates/stackable-telemetry/src/tracing/settings/console_log.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,30 @@ impl ConsoleLogSettingsBuilder {
4848
}
4949

5050
pub fn build(self) -> ConsoleLogSettings {
51-
self.into()
52-
}
53-
}
54-
55-
impl From<ConsoleLogSettingsBuilder> for ConsoleLogSettings {
56-
fn from(value: ConsoleLogSettingsBuilder) -> Self {
57-
Self {
58-
common_settings: value.common_settings,
59-
log_format: value.log_format,
51+
ConsoleLogSettings {
52+
common_settings: self.common_settings,
53+
log_format: self.log_format,
6054
}
6155
}
6256
}
6357

58+
/// This implementation is used to turn the common settings builder into the console log specific
59+
/// settings builder via the [`SettingsBuilder::console_log_settings_builder`] function.
6460
impl From<SettingsBuilder> for ConsoleLogSettingsBuilder {
6561
fn from(value: SettingsBuilder) -> Self {
6662
Self {
67-
common_settings: value.into(),
63+
common_settings: value.build(),
6864
log_format: Format::default(),
6965
}
7066
}
7167
}
7268

69+
/// This implementation is used to build console log settings from common settings without
70+
/// specifying console log specific settings.
7371
impl Build<ConsoleLogSettings> for SettingsBuilder {
7472
fn build(self) -> ConsoleLogSettings {
7573
ConsoleLogSettings {
76-
common_settings: self.into(),
74+
common_settings: self.build(),
7775
..Default::default()
7876
}
7977
}

crates/stackable-telemetry/src/tracing/settings/mod.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ impl Settings {
5252

5353
impl Default for Settings {
5454
fn default() -> Self {
55-
SettingsBuilder::default().into()
55+
SettingsBuilder::default().build()
5656
}
5757
}
5858

@@ -71,7 +71,11 @@ pub trait Build<T> {
7171

7272
impl Build<Settings> for SettingsBuilder {
7373
fn build(self) -> Settings {
74-
self.into()
74+
Settings {
75+
environment_variable: self.environment_variable,
76+
default_level: self.default_level,
77+
enabled: self.enabled,
78+
}
7579
}
7680
}
7781

@@ -134,16 +138,6 @@ impl Default for SettingsBuilder {
134138
}
135139
}
136140

137-
impl From<SettingsBuilder> for Settings {
138-
fn from(value: SettingsBuilder) -> Self {
139-
Self {
140-
environment_variable: value.environment_variable,
141-
default_level: value.default_level,
142-
enabled: value.enabled,
143-
}
144-
}
145-
}
146-
147141
#[cfg(test)]
148142
mod test {
149143
use super::*;

crates/stackable-telemetry/src/tracing/settings/otlp_log.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,28 @@ pub struct OtlpLogSettingsBuilder {
1515

1616
impl OtlpLogSettingsBuilder {
1717
pub fn build(self) -> OtlpLogSettings {
18-
self.into()
18+
OtlpLogSettings {
19+
common_settings: self.common_settings,
20+
}
1921
}
2022
}
2123

24+
/// This implementation is used to turn the common settings builder into the OTLP log specific
25+
/// settings builder via the [`SettingsBuilder::otlp_log_settings_builder`] function.
2226
impl From<SettingsBuilder> for OtlpLogSettingsBuilder {
2327
fn from(value: SettingsBuilder) -> Self {
2428
Self {
25-
common_settings: value.into(),
26-
}
27-
}
28-
}
29-
30-
impl From<OtlpLogSettingsBuilder> for OtlpLogSettings {
31-
fn from(value: OtlpLogSettingsBuilder) -> Self {
32-
Self {
33-
common_settings: value.common_settings,
29+
common_settings: value.build(),
3430
}
3531
}
3632
}
3733

34+
/// This implementation is used to build OTLP log settings from common settings without
35+
/// specifying OTLP log specific settings.
3836
impl Build<OtlpLogSettings> for SettingsBuilder {
3937
fn build(self) -> OtlpLogSettings {
4038
OtlpLogSettings {
41-
common_settings: self.into(),
39+
common_settings: self.build(),
4240
// ..Default::default()
4341
}
4442
}

crates/stackable-telemetry/src/tracing/settings/otlp_trace.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,28 @@ pub struct OtlpTraceSettingsBuilder {
1515

1616
impl OtlpTraceSettingsBuilder {
1717
pub fn build(self) -> OtlpTraceSettings {
18-
self.into()
18+
OtlpTraceSettings {
19+
common_settings: self.common_settings,
20+
}
1921
}
2022
}
2123

24+
/// This implementation is used to turn the common settings builder into the OTLP trace specific
25+
/// settings builder via the [`SettingsBuilder::otlp_trace_settings_builder`] function.
2226
impl From<SettingsBuilder> for OtlpTraceSettingsBuilder {
2327
fn from(value: SettingsBuilder) -> Self {
2428
Self {
25-
common_settings: value.into(),
26-
}
27-
}
28-
}
29-
30-
impl From<OtlpTraceSettingsBuilder> for OtlpTraceSettings {
31-
fn from(value: OtlpTraceSettingsBuilder) -> Self {
32-
Self {
33-
common_settings: value.common_settings,
29+
common_settings: value.build(),
3430
}
3531
}
3632
}
3733

34+
/// This implementation is used to build OTLP trace settings from common settings without
35+
/// specifying OTLP trace specific settings.
3836
impl Build<OtlpTraceSettings> for SettingsBuilder {
3937
fn build(self) -> OtlpTraceSettings {
4038
OtlpTraceSettings {
41-
common_settings: self.into(),
39+
common_settings: self.build(),
4240
// ..Default::default()
4341
}
4442
}

0 commit comments

Comments
 (0)