Skip to content

Commit c8d56c3

Browse files
committed
Fix latest Clippy findings
1 parent f55449c commit c8d56c3

File tree

6 files changed

+23
-38
lines changed

6 files changed

+23
-38
lines changed

src/communication/default_pubsub.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl SubscriptionChangeListener {
153153
fn has_handler(&self, topic: &UUri) -> bool {
154154
self.subscription_change_handlers
155155
.read()
156-
.map_or(false, |handlers| handlers.contains_key(topic))
156+
.is_ok_and(|handlers| handlers.contains_key(topic))
157157
}
158158
}
159159

@@ -541,7 +541,7 @@ mod tests {
541541
};
542542
payload.value == *"Hello"
543543
&& message.is_publish()
544-
&& message.attributes.as_ref().map_or(false, |attribs| {
544+
&& message.attributes.as_ref().is_some_and(|attribs| {
545545
attribs.id.as_ref() == Some(&expected_message_id)
546546
&& attribs.priority.value() == UPriority::UPRIORITY_CS3.value()
547547
&& attribs.ttl == Some(5_000)

src/communication/in_memory_rpc_client.rs

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ impl ResponseListener {
126126
fn contains(&self, reqid: &UUID) -> bool {
127127
self.pending_requests
128128
.lock()
129-
.map_or(false, |pending_requests| {
130-
pending_requests.contains_key(reqid)
131-
})
129+
.is_ok_and(|pending_requests| pending_requests.contains_key(reqid))
132130
}
133131
}
134132

@@ -401,15 +399,12 @@ mod tests {
401399
.expect_do_send()
402400
.once()
403401
.withf(move |request_message| {
404-
request_message
405-
.attributes
406-
.as_ref()
407-
.map_or(false, |attribs| {
408-
attribs.id.as_ref() == Some(&expected_message_id)
409-
&& attribs.priority.value() == UPriority::UPRIORITY_CS6.value()
410-
&& attribs.ttl == Some(5_000)
411-
&& attribs.token == Some("my_token".to_string())
412-
})
402+
request_message.attributes.as_ref().is_some_and(|attribs| {
403+
attribs.id.as_ref() == Some(&expected_message_id)
404+
&& attribs.priority.value() == UPriority::UPRIORITY_CS6.value()
405+
&& attribs.ttl == Some(5_000)
406+
&& attribs.token == Some("my_token".to_string())
407+
})
413408
})
414409
.returning(move |_request_message| {
415410
request_sent_clone.notify_one();
@@ -496,9 +491,7 @@ mod tests {
496491
request_message
497492
.attributes
498493
.as_ref()
499-
.map_or(false, |attribs| {
500-
attribs.id.as_ref() == Some(&expected_message_id)
501-
})
494+
.is_some_and(|attribs| attribs.id.as_ref() == Some(&expected_message_id))
502495
})
503496
.returning(move |_request_message| {
504497
first_request_sent_clone.notify_one();

src/communication/in_memory_rpc_server.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ mod tests {
459459
.attributes
460460
.get_or_default()
461461
.commstatus
462-
.map_or(false, |v| v.enum_value_or_default() == error.get_code())
462+
.is_some_and(|v| v.enum_value_or_default() == error.get_code())
463463
})
464464
.returning(move |_msg| {
465465
notify_clone.notify_one();
@@ -650,7 +650,7 @@ mod tests {
650650
.attributes
651651
.get_or_default()
652652
.commstatus
653-
.map_or(false, |v| v.enum_value_or_default() == error.get_code())
653+
.is_some_and(|v| v.enum_value_or_default() == error.get_code())
654654
&& response_message
655655
.attributes
656656
.get_or_default()
@@ -721,7 +721,7 @@ mod tests {
721721
.attributes
722722
.get_or_default()
723723
.commstatus
724-
.map_or(false, |v| v.enum_value_or_default() == error.get_code())
724+
.is_some_and(|v| v.enum_value_or_default() == error.get_code())
725725
&& response_message
726726
.attributes
727727
.get_or_default()

src/uattributes.rs

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ impl UAttributes {
6868
/// assert!(attribs.is_publish());
6969
/// ```
7070
pub fn is_publish(&self) -> bool {
71-
self.type_
72-
.enum_value()
73-
.map_or(false, |v| v == UMessageType::UMESSAGE_TYPE_PUBLISH)
71+
self.type_.enum_value() == Ok(UMessageType::UMESSAGE_TYPE_PUBLISH)
7472
}
7573

7674
/// Checks if these are the attributes for an RPC Request message.
@@ -87,9 +85,7 @@ impl UAttributes {
8785
/// assert!(attribs.is_request());
8886
/// ```
8987
pub fn is_request(&self) -> bool {
90-
self.type_
91-
.enum_value()
92-
.map_or(false, |v| v == UMessageType::UMESSAGE_TYPE_REQUEST)
88+
self.type_.enum_value() == Ok(UMessageType::UMESSAGE_TYPE_REQUEST)
9389
}
9490

9591
/// Checks if these are the attributes for an RPC Response message.
@@ -106,9 +102,7 @@ impl UAttributes {
106102
/// assert!(attribs.is_response());
107103
/// ```
108104
pub fn is_response(&self) -> bool {
109-
self.type_
110-
.enum_value()
111-
.map_or(false, |v| v == UMessageType::UMESSAGE_TYPE_RESPONSE)
105+
self.type_.enum_value() == Ok(UMessageType::UMESSAGE_TYPE_RESPONSE)
112106
}
113107

114108
/// Checks if these are the attributes for a Notification message.
@@ -125,8 +119,6 @@ impl UAttributes {
125119
/// assert!(attribs.is_notification());
126120
/// ```
127121
pub fn is_notification(&self) -> bool {
128-
self.type_
129-
.enum_value()
130-
.map_or(false, |v| v == UMessageType::UMESSAGE_TYPE_NOTIFICATION)
122+
self.type_.enum_value() == Ok(UMessageType::UMESSAGE_TYPE_NOTIFICATION)
131123
}
132124
}

src/uattributes/uattributesvalidator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub trait UAttributesValidator: Send {
6464
if attributes
6565
.id
6666
.as_ref()
67-
.map_or(false, |id| id.is_uprotocol_uuid())
67+
.is_some_and(|id| id.is_uprotocol_uuid())
6868
{
6969
Ok(())
7070
} else {
@@ -515,7 +515,7 @@ impl ResponseValidator {
515515
if !attributes
516516
.reqid
517517
.as_ref()
518-
.map_or(false, |id| id.is_uprotocol_uuid())
518+
.is_some_and(|id| id.is_uprotocol_uuid())
519519
{
520520
Err(UAttributesError::validation_error(
521521
"Request ID is not a valid uProtocol UUID",

src/umessage.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl UMessage {
9292
pub fn is_publish(&self) -> bool {
9393
self.attributes
9494
.as_ref()
95-
.map_or(false, |attribs| attribs.is_publish())
95+
.is_some_and(|attribs| attribs.is_publish())
9696
}
9797

9898
/// Checks if this is an RPC Request message.
@@ -115,7 +115,7 @@ impl UMessage {
115115
pub fn is_request(&self) -> bool {
116116
self.attributes
117117
.as_ref()
118-
.map_or(false, |attribs| attribs.is_request())
118+
.is_some_and(|attribs| attribs.is_request())
119119
}
120120

121121
/// Checks if this is an RPC Response message.
@@ -138,7 +138,7 @@ impl UMessage {
138138
pub fn is_response(&self) -> bool {
139139
self.attributes
140140
.as_ref()
141-
.map_or(false, |attribs| attribs.is_response())
141+
.is_some_and(|attribs| attribs.is_response())
142142
}
143143

144144
/// Checks if this is a Notification message.
@@ -161,7 +161,7 @@ impl UMessage {
161161
pub fn is_notification(&self) -> bool {
162162
self.attributes
163163
.as_ref()
164-
.map_or(false, |attribs| attribs.is_notification())
164+
.is_some_and(|attribs| attribs.is_notification())
165165
}
166166

167167
/// If `UMessage` payload is available, deserialize it as a protobuf `Message`.

0 commit comments

Comments
 (0)