Skip to content

Commit 069a67b

Browse files
committed
Replace vec! with Vec::{from,new}.
Opinionated change: since Rust 1.44 [1], it has been possible to use Vec::from to write vector literals. On the idea that a method call is a simpler tool than a macro, prefer a method call. (Vec::new is also used, if the vector being created is empty.) [1] rust-lang/rust#68692
1 parent a9eb40e commit 069a67b

File tree

8 files changed

+51
-50
lines changed

8 files changed

+51
-50
lines changed

janus_collector/examples/collect.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ mod tests {
479479
ErrorKind::ValueValidation,
480480
);
481481

482-
let base_arguments = vec![
482+
let base_arguments = Vec::from([
483483
"collect",
484484
"--task-id",
485485
&task_id_encoded,
@@ -495,7 +495,7 @@ mod tests {
495495
"1000000",
496496
"--batch-interval-duration",
497497
"1000",
498-
];
498+
]);
499499

500500
let mut bad_arguments = base_arguments.clone();
501501
bad_arguments.extend(["--vdaf=count", "--buckets=1,2,3,4"]);

janus_core/src/test_util/dummy_vdaf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl vdaf::Client for Vdaf {
137137
&self,
138138
_: &Self::Measurement,
139139
) -> Result<(Self::PublicShare, Vec<Self::InputShare>), VdafError> {
140-
Ok(((), vec![(), ()]))
140+
Ok(((), Vec::from([(), ()])))
141141
}
142142
}
143143

janus_core/src/test_util/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ where
6060
&public_share,
6161
input_share,
6262
)?;
63-
Ok(vec![PrepareTransition::Continue(prep_state, prep_share)])
63+
Ok(Vec::from([PrepareTransition::Continue(
64+
prep_state, prep_share,
65+
)]))
6466
})
6567
.collect::<Result<Vec<Vec<PrepareTransition<V, L>>>, VdafError>>()
6668
.unwrap();

janus_messages/src/bin/dap_decode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ fn decode_dap_message(message_file: &str, media_type: &str) -> Result<Box<dyn De
3030
Box::new(File::open(message_file)?) as Box<dyn Read>
3131
};
3232

33-
let mut message_buf = vec![];
33+
let mut message_buf = Vec::new();
3434
reader.read_to_end(&mut message_buf)?;
3535

3636
let mut binary_message = Cursor::new(message_buf.as_slice());

janus_messages/src/lib.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2665,7 +2665,7 @@ mod tests {
26652665
CollectResp {
26662666
partial_batch_selector: PartialBatchSelector::new_time_interval(),
26672667
report_count: 23,
2668-
encrypted_aggregate_shares: vec![
2668+
encrypted_aggregate_shares: Vec::from([
26692669
HpkeCiphertext::new(
26702670
HpkeConfigId::from(10),
26712671
Vec::from("0123"),
@@ -2676,7 +2676,7 @@ mod tests {
26762676
Vec::from("01234"),
26772677
Vec::from("567"),
26782678
),
2679-
],
2679+
]),
26802680
},
26812681
concat!(
26822682
concat!(
@@ -2747,7 +2747,7 @@ mod tests {
27472747
[4u8; 32],
27482748
)),
27492749
report_count: 23,
2750-
encrypted_aggregate_shares: vec![
2750+
encrypted_aggregate_shares: Vec::from([
27512751
HpkeCiphertext::new(
27522752
HpkeConfigId::from(10),
27532753
Vec::from("0123"),
@@ -2758,7 +2758,7 @@ mod tests {
27582758
Vec::from("01234"),
27592759
Vec::from("567"),
27602760
),
2761-
],
2761+
]),
27622762
},
27632763
concat!(
27642764
concat!(
@@ -2899,12 +2899,12 @@ mod tests {
28992899
job_id: AggregationJobId([u8::MIN; 32]),
29002900
aggregation_parameter: Vec::from("012345"),
29012901
partial_batch_selector: PartialBatchSelector::new_time_interval(),
2902-
report_shares: vec![
2902+
report_shares: Vec::from([
29032903
ReportShare {
29042904
metadata: ReportMetadata::new(
29052905
ReportId::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
29062906
Time::from_seconds_since_epoch(54321),
2907-
vec![Extension::new(ExtensionType::Tbd, Vec::from("0123"))],
2907+
Vec::from([Extension::new(ExtensionType::Tbd, Vec::from("0123"))]),
29082908
),
29092909
public_share: Vec::new(),
29102910
encrypted_input_share: HpkeCiphertext::new(
@@ -2917,7 +2917,7 @@ mod tests {
29172917
metadata: ReportMetadata::new(
29182918
ReportId::from([16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]),
29192919
Time::from_seconds_since_epoch(73542),
2920-
vec![Extension::new(ExtensionType::Tbd, Vec::from("3210"))],
2920+
Vec::from([Extension::new(ExtensionType::Tbd, Vec::from("3210"))]),
29212921
),
29222922
public_share: Vec::from("0123"),
29232923
encrypted_input_share: HpkeCiphertext::new(
@@ -2926,7 +2926,7 @@ mod tests {
29262926
Vec::from("abfd"),
29272927
),
29282928
},
2929-
],
2929+
]),
29302930
},
29312931
concat!(
29322932
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // task_id
@@ -3031,12 +3031,12 @@ mod tests {
30313031
partial_batch_selector: PartialBatchSelector::new_fixed_size(BatchId::from(
30323032
[2u8; 32],
30333033
)),
3034-
report_shares: vec![
3034+
report_shares: Vec::from([
30353035
ReportShare {
30363036
metadata: ReportMetadata::new(
30373037
ReportId::from([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16]),
30383038
Time::from_seconds_since_epoch(54321),
3039-
vec![Extension::new(ExtensionType::Tbd, Vec::from("0123"))],
3039+
Vec::from([Extension::new(ExtensionType::Tbd, Vec::from("0123"))]),
30403040
),
30413041
public_share: Vec::new(),
30423042
encrypted_input_share: HpkeCiphertext::new(
@@ -3049,7 +3049,7 @@ mod tests {
30493049
metadata: ReportMetadata::new(
30503050
ReportId::from([16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]),
30513051
Time::from_seconds_since_epoch(73542),
3052-
vec![Extension::new(ExtensionType::Tbd, Vec::from("3210"))],
3052+
Vec::from([Extension::new(ExtensionType::Tbd, Vec::from("3210"))]),
30533053
),
30543054
public_share: Vec::from("0123"),
30553055
encrypted_input_share: HpkeCiphertext::new(
@@ -3058,7 +3058,7 @@ mod tests {
30583058
Vec::from("abfd"),
30593059
),
30603060
},
3061-
],
3061+
]),
30623062
},
30633063
concat!(
30643064
"FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", // task_id
@@ -3162,7 +3162,7 @@ mod tests {
31623162
roundtrip_encoding(&[
31633163
(
31643164
AggregateInitializeResp {
3165-
prepare_steps: vec![],
3165+
prepare_steps: Vec::new(),
31663166
},
31673167
concat!(concat!(
31683168
// prepare_steps
@@ -3171,7 +3171,7 @@ mod tests {
31713171
),
31723172
(
31733173
AggregateInitializeResp {
3174-
prepare_steps: vec![
3174+
prepare_steps: Vec::from([
31753175
PrepareStep {
31763176
report_id: ReportId::from([
31773177
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
@@ -3184,7 +3184,7 @@ mod tests {
31843184
]),
31853185
result: PrepareStepResult::Finished,
31863186
},
3187-
],
3187+
]),
31883188
},
31893189
concat!(concat!(
31903190
// prepare_steps
@@ -3213,7 +3213,7 @@ mod tests {
32133213
AggregateContinueReq {
32143214
task_id: TaskId::from([u8::MIN; 32]),
32153215
job_id: AggregationJobId([u8::MAX; 32]),
3216-
prepare_steps: vec![
3216+
prepare_steps: Vec::from([
32173217
PrepareStep {
32183218
report_id: ReportId::from([
32193219
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
@@ -3226,7 +3226,7 @@ mod tests {
32263226
]),
32273227
result: PrepareStepResult::Finished,
32283228
},
3229-
],
3229+
]),
32303230
},
32313231
concat!(
32323232
"0000000000000000000000000000000000000000000000000000000000000000", // task_id
@@ -3257,7 +3257,7 @@ mod tests {
32573257
roundtrip_encoding(&[
32583258
(
32593259
AggregateContinueResp {
3260-
prepare_steps: vec![],
3260+
prepare_steps: Vec::new(),
32613261
},
32623262
concat!(concat!(
32633263
// prepare_steps
@@ -3266,7 +3266,7 @@ mod tests {
32663266
),
32673267
(
32683268
AggregateContinueResp {
3269-
prepare_steps: vec![
3269+
prepare_steps: Vec::from([
32703270
PrepareStep {
32713271
report_id: ReportId::from([
32723272
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
@@ -3279,7 +3279,7 @@ mod tests {
32793279
]),
32803280
result: PrepareStepResult::Finished,
32813281
},
3282-
],
3282+
]),
32833283
},
32843284
concat!(concat!(
32853285
// prepare_steps

janus_server/src/bin/aggregator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ mod tests {
155155
metrics_config: generate_metrics_config(),
156156
health_check_listen_address: SocketAddr::from((Ipv4Addr::UNSPECIFIED, 8080)),
157157
},
158-
response_headers: vec![HeaderEntry {
158+
response_headers: Vec::from([HeaderEntry {
159159
name: "name".to_owned(),
160160
value: "value".to_owned(),
161-
}],
161+
}]),
162162
})
163163
}
164164

janus_server/src/binary_utils/job_driver.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -301,12 +301,12 @@ mod tests {
301301

302302
let test_state = Arc::new(Mutex::new(TestState {
303303
job_acquire_counter: 0,
304-
stepped_jobs: vec![],
304+
stepped_jobs: Vec::new(),
305305
}));
306306
// View of incomplete jobs acquired from datastore fed to job finder closure
307-
let incomplete_jobs = Arc::new(vec![
307+
let incomplete_jobs = Arc::new(Vec::from([
308308
// First job finder call: acquire some jobs.
309-
vec![
309+
Vec::from([
310310
IncompleteJob {
311311
task_id: random(),
312312
job_id: random(),
@@ -317,13 +317,13 @@ mod tests {
317317
job_id: random(),
318318
lease_expiry: Time::from_seconds_since_epoch(200),
319319
},
320-
],
320+
]),
321321
// Second job finder call will be immediately after the first: no more jobs
322322
// available yet. Should cause a minimum delay before job finder runs again.
323-
vec![],
323+
Vec::new(),
324324
// Third job finder call: return some new jobs to simulate lease being released and
325325
// re-acquired (it doesn't matter if the task and job IDs change).
326-
vec![
326+
Vec::from([
327327
IncompleteJob {
328328
task_id: random(),
329329
job_id: random(),
@@ -334,8 +334,8 @@ mod tests {
334334
job_id: random(),
335335
lease_expiry: Time::from_seconds_since_epoch(400),
336336
},
337-
],
338-
]);
337+
]),
338+
]));
339339

340340
// Run. Let the aggregation job driver step aggregation jobs, then kill it.
341341
let job_driver = Arc::new(JobDriver::new(
@@ -420,7 +420,7 @@ mod tests {
420420
assert!(final_test_state.job_acquire_counter >= 3);
421421
assert_eq!(
422422
final_test_state.stepped_jobs,
423-
vec![
423+
Vec::from([
424424
// First acquirer run should have caused INCOMPLETE_JOBS[0] to be stepped.
425425
SteppedJob {
426426
observed_jobs_acquire_counter: 1,
@@ -444,7 +444,7 @@ mod tests {
444444
task_id: incomplete_jobs[2][1].task_id,
445445
job_id: incomplete_jobs[2][1].job_id,
446446
},
447-
]
447+
])
448448
);
449449
}
450450
}

janus_server/src/trace.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -188,19 +188,18 @@ pub fn install_trace_subscriber(config: &TraceConfiguration) -> Result<(), Error
188188
map.insert(MetadataKey::from_str(key)?, MetadataValue::try_from(value)?);
189189
}
190190

191-
let tracer =
192-
opentelemetry_otlp::new_pipeline()
193-
.tracing()
194-
.with_exporter(
195-
opentelemetry_otlp::new_exporter()
196-
.tonic()
197-
.with_endpoint(otlp_config.endpoint.clone())
198-
.with_metadata(map),
199-
)
200-
.with_trace_config(trace::config().with_resource(Resource::new(vec![
201-
KeyValue::new(SERVICE_NAME, "janus_server"),
202-
])))
203-
.install_batch(opentelemetry::runtime::Tokio)?;
191+
let tracer = opentelemetry_otlp::new_pipeline()
192+
.tracing()
193+
.with_exporter(
194+
opentelemetry_otlp::new_exporter()
195+
.tonic()
196+
.with_endpoint(otlp_config.endpoint.clone())
197+
.with_metadata(map),
198+
)
199+
.with_trace_config(trace::config().with_resource(Resource::new(Vec::from([
200+
KeyValue::new(SERVICE_NAME, "janus_server"),
201+
]))))
202+
.install_batch(opentelemetry::runtime::Tokio)?;
204203

205204
// Filter out some spans from h2, internal to the OTLP exporter (via tonic). These spans
206205
// would otherwise drown out root spans from the application.

0 commit comments

Comments
 (0)