Skip to content

Commit 570a9ea

Browse files
Fix lint warnings (cloudevents#100)
* Fix clippy warnings Signed-off-by: Francesco Guardiani <[email protected]> * Cargo fmt Signed-off-by: Francesco Guardiani <[email protected]>
1 parent 6ac6534 commit 570a9ea

File tree

15 files changed

+278
-275
lines changed

15 files changed

+278
-275
lines changed

cloudevents-sdk-actix-web/src/server_request.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ impl<'a> BinaryDeserializer for HttpRequestDeserializer<'a> {
6565
)?
6666
}
6767

68-
if self.body.len() != 0 {
68+
if !self.body.is_empty() {
6969
visitor.end_with_data(self.body.to_vec())
7070
} else {
7171
visitor.end()

cloudevents-sdk-rdkafka/src/headers.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ lazy_static! {
2424
attributes_to_headers(SpecVersion::all_attribute_names());
2525
}
2626

27-
pub(crate) static SPEC_VERSION_HEADER: &'static str = "ce_specversion";
28-
pub(crate) static CLOUDEVENTS_JSON_HEADER: &'static str = "application/cloudevents+json";
29-
pub(crate) static CONTENT_TYPE: &'static str = "content-type";
27+
pub(crate) static SPEC_VERSION_HEADER: &str = "ce_specversion";
28+
pub(crate) static CLOUDEVENTS_JSON_HEADER: &str = "application/cloudevents+json";
29+
pub(crate) static CONTENT_TYPE: &str = "content-type";

cloudevents-sdk-rdkafka/src/kafka_consumer_record.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ impl ConsumerRecordDeserializer {
3333
pub fn new(message: &impl Message) -> Result<ConsumerRecordDeserializer> {
3434
Ok(ConsumerRecordDeserializer {
3535
headers: Self::get_kafka_headers(message)?,
36-
payload: message.payload().map(|s| Vec::from(s)),
36+
payload: message.payload().map(Vec::from),
3737
})
3838
}
3939
}

cloudevents-sdk-rdkafka/src/kafka_producer_record.rs

+6
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ impl MessageRecord {
3333
}
3434
}
3535

36+
impl Default for MessageRecord {
37+
fn default() -> Self {
38+
Self::new()
39+
}
40+
}
41+
3642
impl BinarySerializer<MessageRecord> for MessageRecord {
3743
fn set_spec_version(mut self, spec_version: SpecVersion) -> Result<Self> {
3844
self.headers = self

cloudevents-sdk-reqwest/src/client_response.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl BinaryDeserializer for ResponseDeserializer {
6464
)?
6565
}
6666

67-
if self.body.len() != 0 {
67+
if !self.body.is_empty() {
6868
visitor.end_with_data(self.body.to_vec())
6969
} else {
7070
visitor.end()
@@ -84,6 +84,7 @@ impl StructuredDeserializer for ResponseDeserializer {
8484
impl MessageDeserializer for ResponseDeserializer {
8585
fn encoding(&self) -> Encoding {
8686
match (
87+
#[allow(clippy::borrow_interior_mutable_const)]
8788
unwrap_optional_header!(self.headers, reqwest::header::CONTENT_TYPE)
8889
.map(|r| r.ok())
8990
.flatten()

src/event/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ pub(crate) fn default_hostname() -> Url {
261261
.ok()
262262
.map(|s| s.into_string().ok())
263263
.flatten()
264-
.unwrap_or(String::from("localhost".to_string()))
264+
.unwrap_or_else(|| "localhost".to_string())
265265
)
266266
.as_ref(),
267267
)

src/event/event.rs

-255
This file was deleted.

src/event/format.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ macro_rules! parse_field {
5353

5454
macro_rules! parse_data_json {
5555
($in:ident, $error:ty) => {
56-
Ok(serde_json::Value::deserialize($in.into_deserializer())
57-
.map_err(|e| <$error>::custom(e))?)
56+
serde_json::Value::deserialize($in.into_deserializer()).map_err(<$error>::custom)
5857
};
5958
}
6059

@@ -73,7 +72,7 @@ macro_rules! parse_data_string {
7372
macro_rules! parse_json_data_base64 {
7473
($in:ident, $error:ty) => {{
7574
let data = parse_data_base64!($in, $error)?;
76-
serde_json::from_slice(&data).map_err(|e| <$error>::custom(e))
75+
serde_json::from_slice(&data).map_err(<$error>::custom)
7776
}};
7877
}
7978

@@ -113,7 +112,7 @@ pub(crate) trait EventFormatDeserializer {
113112
.into_iter()
114113
.map(|(k, v)| Ok((k, ExtensionValue::deserialize(v.into_deserializer())?)))
115114
.collect::<Result<HashMap<String, ExtensionValue>, serde_value::DeserializerError>>()
116-
.map_err(|e| E::custom(e))?;
115+
.map_err(E::custom)?;
117116

118117
Ok(Event {
119118
attributes,

0 commit comments

Comments
 (0)