Skip to content

Commit ca9c52e

Browse files
authored
Fixed typo for ResponseCode::PrecoditionFailed (#307)
* fixed typo for `ResponseCode::PrecoditionFailed` - changed the enum variant for `ResponseCode::PrecoditionFailed` to `ResponseCode::PrecondtionFailed` - Updated conversions (TryFrom<u16> and From<&ResponseCode>) to map to and from this correct variant. - updated tests that implement this enum variant * Fix clippy::unnecessary_unwrap in create_super_stream #Refactor: Use if let for Option unwrapping in stream_creator Changed binding_keys handling from: - if binding_keys.is_none() + unwrap() To: - if let Some(keys) = binding_keys This is more idiomatic Rust and resolves the clippy unnecessary_unwrap lint error. Additonally refactored the format! specifiers caught by the linter warnings
1 parent 6a98283 commit ca9c52e

File tree

6 files changed

+22
-19
lines changed

6 files changed

+22
-19
lines changed

protocol/src/response/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ pub enum ResponseCode {
4343
FrameTooLarge,
4444
InternalError,
4545
AccessRefused,
46-
PrecoditionFailed,
46+
PreconditionFailed,
4747
PublisherDoesNotExist,
4848
OffsetNotFound,
4949
}

protocol/src/response/shims.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ impl TryFrom<u16> for ResponseCode {
3232
RESPONSE_CODE_FRAME_TOO_LARGE => Ok(ResponseCode::FrameTooLarge),
3333
RESPONSE_CODE_INTERNAL_ERROR => Ok(ResponseCode::InternalError),
3434
RESPONSE_CODE_ACCESS_REFUSED => Ok(ResponseCode::AccessRefused),
35-
RESPONSE_CODE_PRECONDITION_FAILED => Ok(ResponseCode::PrecoditionFailed),
35+
RESPONSE_CODE_PRECONDITION_FAILED => Ok(ResponseCode::PreconditionFailed),
3636
RESPONSE_CODE_PUBLISHER_DOES_NOT_EXIST => Ok(ResponseCode::PublisherDoesNotExist),
3737
RESPONSE_CODE_OFFSET_NOT_FOUND => Ok(ResponseCode::OffsetNotFound),
3838
_ => Err(DecodeError::UnknownResponseCode(value)),
@@ -65,7 +65,7 @@ impl From<&ResponseCode> for u16 {
6565
ResponseCode::FrameTooLarge => RESPONSE_CODE_FRAME_TOO_LARGE,
6666
ResponseCode::InternalError => RESPONSE_CODE_INTERNAL_ERROR,
6767
ResponseCode::AccessRefused => RESPONSE_CODE_ACCESS_REFUSED,
68-
ResponseCode::PrecoditionFailed => RESPONSE_CODE_PRECONDITION_FAILED,
68+
ResponseCode::PreconditionFailed => RESPONSE_CODE_PRECONDITION_FAILED,
6969
ResponseCode::PublisherDoesNotExist => RESPONSE_CODE_PUBLISHER_DOES_NOT_EXIST,
7070
ResponseCode::OffsetNotFound => RESPONSE_CODE_OFFSET_NOT_FOUND,
7171
}

src/bin/perf-producer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,14 @@ async fn main() {
7878
metrics = Vec::with_capacity(50 * 60 * minutes as usize);
7979
tokio::spawn(async move {
8080
let stats = calculate_stats(last_metrics).await;
81-
println!("stats: {:?}", stats);
81+
println!("stats: {stats:?}");
8282
});
8383
}
8484
metrics.push(metric);
8585
}
8686

8787
let stats = calculate_stats(metrics).await;
88-
println!("stats: {:?}", stats);
88+
println!("stats: {stats:?}");
8989
}
9090

9191
async fn calculate_stats(metrics: Vec<Metric>) -> Stats {

src/consumer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ impl ConsumerBuilder {
160160
return Err(ConsumerCreateError::FilteringNotSupport);
161161
}
162162
for (index, item) in filter_input.filter_values.iter().enumerate() {
163-
let key = format!("filter.{}", index);
163+
let key = format!("filter.{index}");
164164
self.properties.insert(key, item.to_owned());
165165
}
166166

src/stream_creator.rs

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,22 @@ impl StreamCreator {
4141
binding_keys: Option<Vec<String>>,
4242
) -> Result<(), StreamCreateError> {
4343
let mut partitions_names = Vec::with_capacity(number_of_partitions);
44-
let mut new_binding_keys: Vec<String> = Vec::with_capacity(number_of_partitions);
45-
46-
if binding_keys.is_none() {
47-
for i in 0..number_of_partitions {
48-
new_binding_keys.push(i.to_string());
49-
partitions_names.push(super_stream.to_owned() + "-" + i.to_string().as_str())
50-
}
44+
let new_binding_keys: Vec<String> = if let Some(keys) = binding_keys {
45+
// Use the provided binding keys
46+
keys.iter()
47+
.map(|binding_key| {
48+
partitions_names.push(super_stream.to_owned() + "-" + binding_key);
49+
binding_key.clone()
50+
})
51+
.collect()
5152
} else {
52-
new_binding_keys = binding_keys.unwrap();
53-
for binding_key in new_binding_keys.iter() {
54-
partitions_names.push(super_stream.to_owned() + "-" + binding_key)
55-
}
56-
}
53+
(0..number_of_partitions)
54+
.map(|i| {
55+
partitions_names.push(super_stream.to_owned() + "-" + &i.to_string());
56+
i.to_string()
57+
})
58+
.collect()
59+
};
5760

5861
let client = self.env.create_client().await?;
5962
let response = client

tests/client_test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ async fn client_declare_delete_publisher_twice_error() {
295295
.await
296296
.unwrap();
297297

298-
assert_eq!(&ResponseCode::PrecoditionFailed, response_error.code());
298+
assert_eq!(&ResponseCode::PreconditionFailed, response_error.code());
299299

300300
let response = test.client.delete_publisher(1).await.unwrap();
301301
assert_eq!(&ResponseCode::Ok, response.code());

0 commit comments

Comments
 (0)