Skip to content

Commit 39a0474

Browse files
committed
Rust: Use an associated type for TestGetValue to make it clear it's an output parameter
Generic parameters are an "input". A trait `TestGetValue<T>` can be implemented for the same type multiple times with different concrete types `T`. That's never needed for `TestGetValue`, we only have a single type that should be returned from `test_get_value`. An associated parameter is the way to do that.
1 parent 319e0d4 commit 39a0474

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+89
-42
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919

2020
[Full changelog](https://github.com/mozilla/glean/compare/v65.1.1...v65.2.0)
2121

22+
* Rust
23+
* Rust: Use an associated type for `TestGetValue` ([#3259](https://github.com/mozilla/glean/pull/3259))
2224
* Swift
2325
* Glean for iOS is now being built with Xcode 16.2 ([#3189](https://github.com/mozilla/glean/pull/3189))
2426
* General

glean-core/rlb/src/private/event.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ impl<K: traits::ExtraKeys> EventMetric<K> {
7272
}
7373

7474
#[inherent]
75-
impl<K> TestGetValue<Vec<RecordedEvent>> for EventMetric<K> {
75+
impl<K> TestGetValue for EventMetric<K> {
76+
type Output = Vec<RecordedEvent>;
77+
7678
pub fn test_get_value(&self, ping_name: Option<String>) -> Option<Vec<RecordedEvent>> {
7779
self.inner.test_get_value(ping_name)
7880
}

glean-core/rlb/src/private/object.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ impl<'a, K> MetricIdentifier<'a> for ObjectMetric<K> {
3939
}
4040
}
4141

42-
impl<K> TestGetValue<JsonValue> for ObjectMetric<K> {
42+
impl<K> TestGetValue for ObjectMetric<K> {
43+
type Output = JsonValue;
44+
4345
/// **Test-only API (exported for FFI purposes).**
4446
///
4547
/// Gets the currently stored value as JSON-encoded string.

glean-core/src/metrics/boolean.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,8 @@ impl BooleanMetric {
120120
}
121121
}
122122

123-
impl TestGetValue<bool> for BooleanMetric {
123+
impl TestGetValue for BooleanMetric {
124+
type Output = bool;
124125
/// **Test-only API (exported for FFI purposes).**
125126
///
126127
/// Gets the currently stored value as a boolean.

glean-core/src/metrics/counter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ impl CounterMetric {
157157
}
158158
}
159159

160-
impl TestGetValue<i32> for CounterMetric {
160+
impl TestGetValue for CounterMetric {
161+
type Output = i32;
162+
161163
/// **Test-only API (exported for FFI purposes).**
162164
///
163165
/// Gets the currently stored value as an integer.

glean-core/src/metrics/custom_distribution.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,9 @@ impl CustomDistributionMetric {
303303
}
304304
}
305305

306-
impl TestGetValue<DistributionData> for CustomDistributionMetric {
306+
impl TestGetValue for CustomDistributionMetric {
307+
type Output = DistributionData;
308+
307309
/// **Test-only API (exported for FFI purposes).**
308310
///
309311
/// Gets the currently stored value as an integer.

glean-core/src/metrics/datetime.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,9 @@ impl DatetimeMetric {
277277
}
278278
}
279279

280-
impl TestGetValue<Datetime> for DatetimeMetric {
280+
impl TestGetValue for DatetimeMetric {
281+
type Output = Datetime;
282+
281283
/// **Test-only API (exported for FFI purposes).**
282284
///
283285
/// Gets the stored datetime value.

glean-core/src/metrics/denominator.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ impl DenominatorMetric {
127127
}
128128
}
129129

130-
impl TestGetValue<i32> for DenominatorMetric {
130+
impl TestGetValue for DenominatorMetric {
131+
type Output = i32;
132+
131133
/// **Test-only API (exported for FFI purposes).**
132134
///
133135
/// Gets the currently stored value as an integer.

glean-core/src/metrics/dual_labeled_counter.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,9 @@ impl DualLabeledCounterMetric {
231231
}
232232
}
233233

234-
impl TestGetValue<HashMap<String, HashMap<String, i32>>> for DualLabeledCounterMetric {
234+
impl TestGetValue for DualLabeledCounterMetric {
235+
type Output = HashMap<String, HashMap<String, i32>>;
236+
235237
fn test_get_value(
236238
&self,
237239
ping_name: Option<String>,

glean-core/src/metrics/event.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,9 @@ impl EventMetric {
212212
}
213213
}
214214

215-
impl TestGetValue<Vec<RecordedEvent>> for EventMetric {
215+
impl TestGetValue for EventMetric {
216+
type Output = Vec<RecordedEvent>;
217+
216218
/// **Test-only API (exported for FFI purposes).**
217219
///
218220
/// Get the vector of currently stored events for this event metric.

0 commit comments

Comments
 (0)