[ISSUE #1659]🚀Add AckStatus enum🔥#1660
Conversation
WalkthroughThe changes introduce a new public module Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
|
🔊@mxsm 🚀Thanks for your contribution 🎉. CodeRabbit(AI) will review your code first 🔥 |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1660 +/- ##
==========================================
+ Coverage 27.34% 27.49% +0.14%
==========================================
Files 466 467 +1
Lines 62487 62617 +130
==========================================
+ Hits 17089 17216 +127
- Misses 45398 45401 +3 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Outside diff range and nitpick comments (2)
rocketmq-client/src/consumer/ack_status.rs (2)
25-30: Enhance variant documentationWhile the enum design is clean, the inline comments could be more descriptive to better explain the use cases for each variant.
Consider updating the comments to:
- Ok, //ack success - NotExist, // msg not exist + /// Indicates successful message acknowledgment + Ok, + /// Indicates the message to be acknowledged does not exist + NotExist,
143-236: Enhance test coverageWhile the test suite is comprehensive, consider adding:
- Tests for deserialize error cases
- Property-based tests for round-trip conversions
Add these test cases:
#[test] fn ack_status_deserialize_error() { let result: Result<AckStatus, _> = serde_json::from_str("\"INVALID\""); assert!(result.is_err()); } #[cfg(test)] #[cfg(feature = "quickcheck")] mod property_tests { use quickcheck_macros::quickcheck; #[quickcheck] fn round_trip_through_i32(status: AckStatus) -> bool { let num: i32 = status.into(); let roundtrip: AckStatus = num.into(); status == roundtrip } }
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (2)
rocketmq-client/src/consumer.rs(1 hunks)rocketmq-client/src/consumer/ack_status.rs(1 hunks)
🔇 Additional comments (2)
rocketmq-client/src/consumer.rs (1)
17-17: LGTM! Module declaration follows crate's visibility patterns
The pub(crate) visibility modifier appropriately restricts the module access to within the crate, following good encapsulation practices.
rocketmq-client/src/consumer/ack_status.rs (1)
116-141: LGTM! Solid serialization implementation
The serialization implementation properly handles errors and follows serde best practices.
| impl AckStatus { | ||
| pub fn from_i32(value: i32) -> Option<Self> { | ||
| match value { | ||
| 0 => Some(AckStatus::Ok), | ||
| 1 => Some(AckStatus::NotExist), | ||
| _ => None, | ||
| } | ||
| } | ||
|
|
||
| pub fn to_i32(self) -> i32 { | ||
| match self { | ||
| AckStatus::Ok => 0, | ||
| AckStatus::NotExist => 1, | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
🛠️ Refactor suggestion
Reduce code duplication in numeric conversions
There's duplicate logic between from_i32/to_i32 methods and the From/Into implementations. Consider consolidating these conversions.
impl AckStatus {
- pub fn from_i32(value: i32) -> Option<Self> {
- match value {
- 0 => Some(AckStatus::Ok),
- 1 => Some(AckStatus::NotExist),
- _ => None,
- }
- }
+ pub fn from_i32(value: i32) -> Option<Self> {
+ Self::try_from(value).ok()
+ }
- pub fn to_i32(self) -> i32 {
- match self {
- AckStatus::Ok => 0,
- AckStatus::NotExist => 1,
- }
- }
+ pub fn to_i32(self) -> i32 {
+ self.into()
+ }
}Also applies to: 87-104
| impl From<String> for AckStatus { | ||
| fn from(s: String) -> Self { | ||
| match s.as_str() { | ||
| "OK" => AckStatus::Ok, | ||
| "NO_EXIST" => AckStatus::NotExist, | ||
| _ => AckStatus::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<&str> for AckStatus { | ||
| fn from(s: &str) -> Self { | ||
| match s { | ||
| "OK" => AckStatus::Ok, | ||
| "NO_EXIST" => AckStatus::NotExist, | ||
| _ => AckStatus::default(), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| impl From<AckStatus> for String { | ||
| fn from(status: AckStatus) -> Self { | ||
| match status { | ||
| AckStatus::Ok => "OK".to_string(), | ||
| AckStatus::NotExist => "NO_EXIST".to_string(), | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Consider consistent error handling across conversions
The From implementations silently default to Ok for unknown values, while the Deserialize implementation returns an error. This inconsistency could lead to unexpected behavior.
Consider using a TryFrom implementation instead:
-impl From<String> for AckStatus {
+impl TryFrom<String> for AckStatus {
+ type Error = String;
fn from(s: String) -> Self {
match s.as_str() {
"OK" => AckStatus::Ok,
"NO_EXIST" => AckStatus::NotExist,
- _ => AckStatus::default(),
+ _ => Err(format!("Invalid AckStatus value: {}", s)),
}
}
}Committable suggestion skipped: line range outside the PR's diff.
Which Issue(s) This PR Fixes(Closes)
Fixes #1659
Brief Description
How Did You Test This Change?
Summary by CodeRabbit
New Features
Tests