Skip to content

Commit 4b84601

Browse files
committed
refactor: rename T and U type parameters to Config and RoleConfig
1 parent 0c5ac02 commit 4b84601

File tree

2 files changed

+58
-58
lines changed

2 files changed

+58
-58
lines changed

crates/stackable-operator/src/product_config_utils.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -174,19 +174,19 @@ pub fn config_for_role_and_group<'a>(
174174
/// - `roles`: A map keyed by role names. The value is a tuple of a vector of `PropertyNameKind`
175175
/// like (Cli, Env or Files) and [`crate::role_utils::Role`] with a boxed [`Configuration`].
176176
#[allow(clippy::type_complexity)]
177-
pub fn transform_all_roles_to_config<T, ConfigOverrides, U, CommonConfig>(
178-
resource: &T::Configurable,
177+
pub fn transform_all_roles_to_config<Config, ConfigOverrides, RoleConfig, CommonConfig>(
178+
resource: &Config::Configurable,
179179
roles: HashMap<
180180
String,
181181
(
182182
Vec<PropertyNameKind>,
183-
Role<T, ConfigOverrides, U, CommonConfig>,
183+
Role<Config, ConfigOverrides, RoleConfig, CommonConfig>,
184184
),
185185
>,
186186
) -> Result<RoleConfigByPropertyKind>
187187
where
188-
T: Configuration,
189-
U: Default + JsonSchema + Serialize,
188+
Config: Configuration,
189+
RoleConfig: Default + JsonSchema + Serialize,
190190
CommonConfig: Default + JsonSchema + Serialize,
191191
ConfigOverrides: Default + JsonSchema + Serialize + KeyValueOverridesProvider,
192192
{
@@ -384,15 +384,15 @@ fn process_validation_result(
384384
/// - `role_name` - The name of the role.
385385
/// - `role` - The role for which to transform the configuration parameters.
386386
/// - `property_kinds` - Used as "buckets" to partition the configuration properties by.
387-
fn transform_role_to_config<T, ConfigOverrides, U, CommonConfig>(
388-
resource: &T::Configurable,
387+
fn transform_role_to_config<Config, ConfigOverrides, RoleConfig, CommonConfig>(
388+
resource: &Config::Configurable,
389389
role_name: &str,
390-
role: &Role<T, ConfigOverrides, U, CommonConfig>,
390+
role: &Role<Config, ConfigOverrides, RoleConfig, CommonConfig>,
391391
property_kinds: &[PropertyNameKind],
392392
) -> Result<RoleGroupConfigByPropertyKind>
393393
where
394-
T: Configuration,
395-
U: Default + JsonSchema + Serialize,
394+
Config: Configuration,
395+
RoleConfig: Default + JsonSchema + Serialize,
396396
CommonConfig: Default + JsonSchema + Serialize,
397397
ConfigOverrides: Default + JsonSchema + Serialize + KeyValueOverridesProvider,
398398
{
@@ -449,14 +449,14 @@ where
449449
/// - `role_name` - Not used directly but passed on to the `Configuration::compute_*` calls.
450450
/// - `config` - The configuration properties to partition.
451451
/// - `property_kinds` - The "buckets" used to partition the configuration properties.
452-
fn parse_role_config<T, CommonConfig, ConfigOverrides>(
453-
resource: &<T as Configuration>::Configurable,
452+
fn parse_role_config<Config, CommonConfig, ConfigOverrides>(
453+
resource: &<Config as Configuration>::Configurable,
454454
role_name: &str,
455-
config: &CommonConfiguration<T, CommonConfig, ConfigOverrides>,
455+
config: &CommonConfiguration<Config, CommonConfig, ConfigOverrides>,
456456
property_kinds: &[PropertyNameKind],
457457
) -> Result<HashMap<PropertyNameKind, BTreeMap<String, Option<String>>>>
458458
where
459-
T: Configuration,
459+
Config: Configuration,
460460
{
461461
let mut result = HashMap::new();
462462
for property_kind in property_kinds {
@@ -479,12 +479,12 @@ where
479479
Ok(result)
480480
}
481481

482-
fn parse_role_overrides<T, CommonConfig, ConfigOverrides>(
483-
config: &CommonConfiguration<T, CommonConfig, ConfigOverrides>,
482+
fn parse_role_overrides<Config, CommonConfig, ConfigOverrides>(
483+
config: &CommonConfiguration<Config, CommonConfig, ConfigOverrides>,
484484
property_kinds: &[PropertyNameKind],
485485
) -> Result<HashMap<PropertyNameKind, BTreeMap<String, Option<String>>>>
486486
where
487-
T: Configuration,
487+
Config: Configuration,
488488
ConfigOverrides: KeyValueOverridesProvider,
489489
{
490490
let mut result = HashMap::new();
@@ -517,12 +517,12 @@ where
517517
Ok(result)
518518
}
519519

520-
fn parse_file_overrides<T, CommonConfig, ConfigOverrides>(
521-
config: &CommonConfiguration<T, CommonConfig, ConfigOverrides>,
520+
fn parse_file_overrides<Config, CommonConfig, ConfigOverrides>(
521+
config: &CommonConfiguration<Config, CommonConfig, ConfigOverrides>,
522522
file: &str,
523523
) -> Result<BTreeMap<String, Option<String>>>
524524
where
525-
T: Configuration,
525+
Config: Configuration,
526526
ConfigOverrides: KeyValueOverridesProvider,
527527
{
528528
Ok(config.config_overrides.get_key_value_overrides(file))

crates/stackable-operator/src/role_utils.rs

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -118,19 +118,19 @@ pub enum Error {
118118
#[serde(
119119
rename_all = "camelCase",
120120
bound(
121-
deserialize = "T: Default + Deserialize<'de>, CommonConfig: Default + Deserialize<'de>, ConfigOverrides: Default + Deserialize<'de>"
121+
deserialize = "Config: Default + Deserialize<'de>, CommonConfig: Default + Deserialize<'de>, ConfigOverrides: Default + Deserialize<'de>"
122122
)
123123
)]
124124
#[schemars(
125-
bound = "T: JsonSchema, CommonConfig: JsonSchema, ConfigOverrides: Default + JsonSchema"
125+
bound = "Config: JsonSchema, CommonConfig: JsonSchema, ConfigOverrides: Default + JsonSchema"
126126
)]
127-
pub struct CommonConfiguration<T, CommonConfig, ConfigOverrides> {
127+
pub struct CommonConfiguration<Config, CommonConfig, ConfigOverrides> {
128128
#[serde(default)]
129-
// We can't depend on T being `Default`, since that trait is not object-safe
129+
// We can't depend on Config being `Default`, since that trait is not object-safe
130130
// We only need to generate schemas for fully specified types, but schemars_derive
131131
// does not support specifying custom bounds.
132132
#[schemars(default = "Self::default_config")]
133-
pub config: T,
133+
pub config: Config,
134134

135135
/// The `configOverrides` can be used to configure properties in product config files
136136
/// that are not exposed in the CRD. Read the
@@ -174,8 +174,8 @@ pub struct CommonConfiguration<T, CommonConfig, ConfigOverrides> {
174174
pub product_specific_common_config: CommonConfig,
175175
}
176176

177-
impl<T, CommonConfig, ConfigOverrides>
178-
CommonConfiguration<T, CommonConfig, ConfigOverrides>
177+
impl<Config, CommonConfig, ConfigOverrides>
178+
CommonConfiguration<Config, CommonConfig, ConfigOverrides>
179179
{
180180
fn default_config() -> serde_json::Value {
181181
serde_json::json!({})
@@ -296,45 +296,45 @@ impl JvmArgumentOverrides {
296296
// Everything below is only a "normal" comment, not rustdoc - so we don't bloat the CRD documentation
297297
// with technical (Rust) details.
298298
//
299-
// `T` here is the `config` shared between role and roleGroup.
299+
// `Config` here is the `config` shared between role and roleGroup.
300300
//
301-
// `U` here is the `roleConfig` only available on the role. It defaults to [`GenericRoleConfig`], which is
301+
// `RoleConfig` here is the `roleConfig` only available on the role. It defaults to [`GenericRoleConfig`], which is
302302
// sufficient for most of the products. There are some exceptions, where e.g. [`EmptyRoleConfig`] is used.
303303
// However, product-operators can define their own - custom - struct and use that here.
304304
#[derive(Clone, Debug, Default, Deserialize, JsonSchema, PartialEq, Serialize)]
305305
#[serde(rename_all = "camelCase")]
306306
pub struct Role<
307-
T,
307+
Config,
308308
ConfigOverrides,
309-
U = GenericRoleConfig,
309+
RoleConfig = GenericRoleConfig,
310310
CommonConfig = GenericCommonConfig,
311311
> where
312312
// Don't remove this trait bounds!!!
313313
// We don't know why, but if you remove either of them, the generated default value in the CRDs will
314314
// be missing!
315-
U: Default + JsonSchema + Serialize,
315+
RoleConfig: Default + JsonSchema + Serialize,
316316
CommonConfig: Default + JsonSchema + Serialize,
317317
ConfigOverrides: Default + JsonSchema + Serialize,
318318
{
319319
#[serde(
320320
flatten,
321321
bound(
322-
deserialize = "T: Default + Deserialize<'de>, CommonConfig: Deserialize<'de>, ConfigOverrides: Deserialize<'de>"
322+
deserialize = "Config: Default + Deserialize<'de>, CommonConfig: Deserialize<'de>, ConfigOverrides: Deserialize<'de>"
323323
)
324324
)]
325-
pub config: CommonConfiguration<T, CommonConfig, ConfigOverrides>,
325+
pub config: CommonConfiguration<Config, CommonConfig, ConfigOverrides>,
326326

327327
#[serde(default)]
328-
pub role_config: U,
328+
pub role_config: RoleConfig,
329329

330-
pub role_groups: HashMap<String, RoleGroup<T, CommonConfig, ConfigOverrides>>,
330+
pub role_groups: HashMap<String, RoleGroup<Config, CommonConfig, ConfigOverrides>>,
331331
}
332332

333-
impl<T, ConfigOverrides, U, CommonConfig>
334-
Role<T, ConfigOverrides, U, CommonConfig>
333+
impl<Config, ConfigOverrides, RoleConfig, CommonConfig>
334+
Role<Config, ConfigOverrides, RoleConfig, CommonConfig>
335335
where
336-
T: Configuration + 'static,
337-
U: Default + JsonSchema + Serialize,
336+
Config: Configuration + 'static,
337+
RoleConfig: Default + JsonSchema + Serialize,
338338
CommonConfig: Default + JsonSchema + Serialize + Clone,
339339
ConfigOverrides: Default + JsonSchema + Serialize,
340340
{
@@ -346,15 +346,15 @@ where
346346
pub fn erase(
347347
self,
348348
) -> Role<
349-
Box<dyn Configuration<Configurable = T::Configurable>>,
349+
Box<dyn Configuration<Configurable = Config::Configurable>>,
350350
ConfigOverrides,
351-
U,
351+
RoleConfig,
352352
CommonConfig,
353353
> {
354354
Role {
355355
config: CommonConfiguration {
356356
config: Box::new(self.config.config)
357-
as Box<dyn Configuration<Configurable = T::Configurable>>,
357+
as Box<dyn Configuration<Configurable = Config::Configurable>>,
358358
config_overrides: self.config.config_overrides,
359359
env_overrides: self.config.env_overrides,
360360
cli_overrides: self.config.cli_overrides,
@@ -371,7 +371,7 @@ where
371371
RoleGroup {
372372
config: CommonConfiguration {
373373
config: Box::new(group.config.config)
374-
as Box<dyn Configuration<Configurable = T::Configurable>>,
374+
as Box<dyn Configuration<Configurable = Config::Configurable>>,
375375
config_overrides: group.config.config_overrides,
376376
env_overrides: group.config.env_overrides,
377377
cli_overrides: group.config.cli_overrides,
@@ -389,9 +389,9 @@ where
389389
}
390390
}
391391

392-
impl<T, ConfigOverrides, U> Role<T, ConfigOverrides, U, JavaCommonConfig>
392+
impl<Config, ConfigOverrides, RoleConfig> Role<Config, ConfigOverrides, RoleConfig, JavaCommonConfig>
393393
where
394-
U: Default + JsonSchema + Serialize,
394+
RoleConfig: Default + JsonSchema + Serialize,
395395
ConfigOverrides: Default + JsonSchema + Serialize,
396396
{
397397
/// Merges jvm argument overrides from
@@ -445,30 +445,30 @@ pub struct EmptyRoleConfig {}
445445
#[serde(
446446
rename_all = "camelCase",
447447
bound(
448-
deserialize = "T: Default + Deserialize<'de>, CommonConfig: Default + Deserialize<'de>, ConfigOverrides: Default + Deserialize<'de>"
448+
deserialize = "Config: Default + Deserialize<'de>, CommonConfig: Default + Deserialize<'de>, ConfigOverrides: Default + Deserialize<'de>"
449449
)
450450
)]
451451
#[schemars(
452-
bound = "T: JsonSchema, CommonConfig: JsonSchema, ConfigOverrides: Default + JsonSchema"
452+
bound = "Config: JsonSchema, CommonConfig: JsonSchema, ConfigOverrides: Default + JsonSchema"
453453
)]
454-
pub struct RoleGroup<T, CommonConfig, ConfigOverrides> {
454+
pub struct RoleGroup<Config, CommonConfig, ConfigOverrides> {
455455
#[serde(flatten)]
456-
pub config: CommonConfiguration<T, CommonConfig, ConfigOverrides>,
456+
pub config: CommonConfiguration<Config, CommonConfig, ConfigOverrides>,
457457
pub replicas: Option<u16>,
458458
}
459459

460-
impl<T, CommonConfig, ConfigOverrides>
461-
RoleGroup<T, CommonConfig, ConfigOverrides>
460+
impl<Config, CommonConfig, ConfigOverrides>
461+
RoleGroup<Config, CommonConfig, ConfigOverrides>
462462
{
463-
pub fn validate_config<C, U>(
463+
pub fn validate_config<C, RoleConfig>(
464464
&self,
465-
role: &Role<T, ConfigOverrides, U, CommonConfig>,
466-
default_config: &T,
465+
role: &Role<Config, ConfigOverrides, RoleConfig, CommonConfig>,
466+
default_config: &Config,
467467
) -> Result<C, fragment::ValidationError>
468468
where
469-
C: FromFragment<Fragment = T>,
470-
T: Merge + Clone,
471-
U: Default + JsonSchema + Serialize,
469+
C: FromFragment<Fragment = Config>,
470+
Config: Merge + Clone,
471+
RoleConfig: Default + JsonSchema + Serialize,
472472
CommonConfig: Default + JsonSchema + Serialize,
473473
ConfigOverrides: Default + JsonSchema + Serialize,
474474
{

0 commit comments

Comments
 (0)