Skip to content

Commit f2273d3

Browse files
committed
fix clippy lints
1 parent 5b42d74 commit f2273d3

File tree

12 files changed

+27
-30
lines changed

12 files changed

+27
-30
lines changed

rust/signed_doc/src/builder.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ impl Builder {
3939
///
4040
/// # Errors
4141
/// - Fails if it is invalid metadata JSON object.
42-
#[must_use]
4342
pub fn with_json_metadata(mut self, json: serde_json::Value) -> anyhow::Result<Self> {
4443
self.metadata = Some(serde_json::from_value(json)?);
4544
Ok(self)

rust/signed_doc/src/content.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,9 @@ impl Content {
6161
///
6262
/// # Errors
6363
/// - Missing Document content
64-
#[must_use]
6564
pub fn decoded_bytes(&self) -> anyhow::Result<&[u8]> {
6665
self.data
67-
.as_ref()
68-
.map(|v| v.as_slice())
66+
.as_deref()
6967
.ok_or(anyhow::anyhow!("Missing Document content"))
7068
}
7169

@@ -89,6 +87,6 @@ impl Content {
8987
/// If content is empty returns `0`.
9088
#[must_use]
9189
pub fn size(&self) -> usize {
92-
self.data.as_ref().map(|v| v.len()).unwrap_or_default()
90+
self.data.as_ref().map(Vec::len).unwrap_or_default()
9391
}
9492
}

rust/signed_doc/src/lib.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ impl CatalystSignedDocument {
8484
///
8585
/// # Errors
8686
/// - Missing 'type' field.
87-
#[must_use]
8887
pub fn doc_type(&self) -> anyhow::Result<UuidV4> {
8988
self.inner.metadata.doc_type()
9089
}
@@ -93,7 +92,6 @@ impl CatalystSignedDocument {
9392
///
9493
/// # Errors
9594
/// - Missing 'id' field.
96-
#[must_use]
9795
pub fn doc_id(&self) -> anyhow::Result<UuidV7> {
9896
self.inner.metadata.doc_id()
9997
}
@@ -102,7 +100,6 @@ impl CatalystSignedDocument {
102100
///
103101
/// # Errors
104102
/// - Missing 'ver' field.
105-
#[must_use]
106103
pub fn doc_ver(&self) -> anyhow::Result<UuidV7> {
107104
self.inner.metadata.doc_ver()
108105
}
@@ -117,7 +114,6 @@ impl CatalystSignedDocument {
117114
///
118115
/// # Errors
119116
/// - Missing 'content-type' field.
120-
#[must_use]
121117
pub fn doc_content_type(&self) -> anyhow::Result<ContentType> {
122118
self.inner.metadata.content_type()
123119
}
@@ -228,7 +224,6 @@ impl CatalystSignedDocument {
228224
///
229225
/// # Errors
230226
/// Fails if the `CatalystSignedDocument` object is not valid.
231-
#[must_use]
232227
pub fn into_builder(self) -> anyhow::Result<Builder> {
233228
if self.report().is_problematic() {
234229
anyhow::bail!("Invalid Document");

rust/signed_doc/src/metadata/content_encoding.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub enum ContentEncoding {
1616

1717
impl ContentEncoding {
1818
/// Compress a Brotli payload
19+
///
20+
/// # Errors
21+
/// Returns compression failure
1922
pub fn encode(self, mut payload: &[u8]) -> anyhow::Result<Vec<u8>> {
2023
match self {
2124
Self::Brotli => {
@@ -28,6 +31,9 @@ impl ContentEncoding {
2831
}
2932

3033
/// Decompress a Brotli payload
34+
///
35+
/// # Errors
36+
/// Returns decompression failure
3137
pub fn decode(self, mut payload: &[u8]) -> anyhow::Result<Vec<u8>> {
3238
match self {
3339
Self::Brotli => {

rust/signed_doc/src/metadata/extra_fields.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl ExtraFields {
177177
error_report.conversion_error(
178178
"CBOR COSE protected header doc ref",
179179
&format!("{cbor_doc_ref:?}"),
180-
&format!("Expected a CBOR DocumentRef"),
180+
"Expected a CBOR DocumentRef",
181181
&format!("{CONTEXT}, DocumentRef"),
182182
);
183183
};
@@ -192,7 +192,7 @@ impl ExtraFields {
192192
error_report.conversion_error(
193193
"CBOR COSE protected header document template",
194194
&format!("{cbor_doc_template:?}"),
195-
&format!("Expected a CBOR DocumentRef"),
195+
"Expected a CBOR DocumentRef",
196196
&format!("{CONTEXT}, DocumentRef"),
197197
);
198198
}
@@ -207,7 +207,7 @@ impl ExtraFields {
207207
error_report.conversion_error(
208208
"CBOR COSE protected header document reply",
209209
&format!("{cbor_doc_reply:?}"),
210-
&format!("Expected a CBOR DocumentRef"),
210+
"Expected a CBOR DocumentRef",
211211
&format!("{CONTEXT}, DocumentRef"),
212212
);
213213
}
@@ -222,7 +222,7 @@ impl ExtraFields {
222222
error_report.conversion_error(
223223
"COSE protected header document section",
224224
&format!("{cbor_doc_section:?}"),
225-
&format!("Must be a valid CBOR encoded String JSON Path"),
225+
"Must be a valid CBOR encoded String JSON Path",
226226
&format!("{CONTEXT}, converting document section to String JSON Path"),
227227
);
228228
}
@@ -242,7 +242,7 @@ impl ExtraFields {
242242
error_report.conversion_error(
243243
&format!("COSE protected header collaborator index {ids}"),
244244
&format!("{collaborator:?}"),
245-
&format!("Expected a CBOR String"),
245+
"Expected a CBOR String",
246246
&format!("{CONTEXT}, converting collaborator to String"),
247247
);
248248
},
@@ -253,7 +253,7 @@ impl ExtraFields {
253253
error_report.conversion_error(
254254
"CBOR COSE protected header collaborators",
255255
&format!("{cbor_doc_collabs:?}"),
256-
&format!("Expected a CBOR Array"),
256+
"Expected a CBOR Array",
257257
&format!("{CONTEXT}, converting collaborators to Array"),
258258
);
259259
};
@@ -268,7 +268,7 @@ impl ExtraFields {
268268
error_report.conversion_error(
269269
"CBOR COSE protected header brand ID",
270270
&format!("{cbor_doc_brand_id:?}"),
271-
&format!("Expected a CBOR UUID"),
271+
"Expected a CBOR UUID",
272272
&format!("{CONTEXT}, decoding CBOR UUID for brand ID"),
273273
);
274274
}
@@ -283,7 +283,7 @@ impl ExtraFields {
283283
error_report.conversion_error(
284284
"CBOR COSE protected header campaign ID",
285285
&format!("{cbor_doc_campaign_id:?}"),
286-
&format!("Expected a CBOR UUID"),
286+
"Expected a CBOR UUID",
287287
&format!("{CONTEXT}, decoding CBOR UUID for campaign ID"),
288288
);
289289
}
@@ -298,7 +298,7 @@ impl ExtraFields {
298298
error_report.conversion_error(
299299
"CBOR COSE protected header election ID",
300300
&format!("{cbor_doc_election_id:?}"),
301-
&format!("Expected a CBOR UUID"),
301+
"Expected a CBOR UUID",
302302
&format!("{CONTEXT}, decoding CBOR UUID for election ID"),
303303
);
304304
}
@@ -313,7 +313,7 @@ impl ExtraFields {
313313
error_report.conversion_error(
314314
"CBOR COSE protected header category ID",
315315
&format!("{cbor_doc_category_id:?}"),
316-
&format!("Expected a CBOR UUID"),
316+
"Expected a CBOR UUID",
317317
&format!("{CONTEXT}, decoding CBOR UUID for category ID"),
318318
);
319319
}

rust/signed_doc/src/metadata/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ impl Metadata {
6464
///
6565
/// # Errors
6666
/// - Missing 'alg' field.
67-
#[must_use]
6867
pub fn algorithm(&self) -> anyhow::Result<Algorithm> {
6968
self.alg.ok_or(anyhow::anyhow!("Missing 'alg' field"))
7069
}
@@ -73,7 +72,6 @@ impl Metadata {
7372
///
7473
/// # Errors
7574
/// - Missing 'type' field.
76-
#[must_use]
7775
pub fn doc_type(&self) -> anyhow::Result<UuidV4> {
7876
self.doc_type.ok_or(anyhow::anyhow!("Missing 'type' field"))
7977
}
@@ -82,7 +80,6 @@ impl Metadata {
8280
///
8381
/// # Errors
8482
/// - Missing 'id' field.
85-
#[must_use]
8683
pub fn doc_id(&self) -> anyhow::Result<UuidV7> {
8784
self.id.ok_or(anyhow::anyhow!("Missing 'id' field"))
8885
}
@@ -91,7 +88,6 @@ impl Metadata {
9188
///
9289
/// # Errors
9390
/// - Missing 'ver' field.
94-
#[must_use]
9591
pub fn doc_ver(&self) -> anyhow::Result<UuidV7> {
9692
self.ver.ok_or(anyhow::anyhow!("Missing 'ver' field"))
9793
}
@@ -100,7 +96,6 @@ impl Metadata {
10096
///
10197
/// # Errors
10298
/// - Missing 'content-type' field.
103-
#[must_use]
10499
pub fn content_type(&self) -> anyhow::Result<ContentType> {
105100
self.content_type
106101
.ok_or(anyhow::anyhow!("Missing 'content-type' field"))

rust/signed_doc/src/metadata/section.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ impl<'de> Deserialize<'de> for Section {
2626
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
2727
where D: serde::Deserializer<'de> {
2828
let str = String::deserialize(deserializer)?;
29-
Ok(Self::from_str(&str).map_err(|e| serde::de::Error::custom(e))?)
29+
Self::from_str(&str).map_err(serde::de::Error::custom)
3030
}
3131
}
3232

@@ -35,7 +35,7 @@ impl FromStr for Section {
3535

3636
fn from_str(s: &str) -> Result<Self, Self::Err> {
3737
Ok(Self(
38-
jsonpath_rust::JsonPath::<serde_json::Value>::from_str(&s)?,
38+
jsonpath_rust::JsonPath::<serde_json::Value>::from_str(s)?,
3939
))
4040
}
4141
}
@@ -53,6 +53,6 @@ impl TryFrom<&Value> for Section {
5353
let str = val
5454
.as_text()
5555
.ok_or(anyhow::anyhow!("Not a cbor string type"))?;
56-
Ok(Self::from_str(str)?)
56+
Self::from_str(str)
5757
}
5858
}

rust/signed_doc/src/validator/rules/category.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ use crate::{
88
/// `category_id` field validation rule
99
#[derive(Clone, Debug, PartialEq)]
1010
pub(crate) enum CategoryRule {
11-
/// Is 'category_id' specified
11+
/// Is `category_id` specified
1212
Specified {
1313
/// optional flag for the `category_id` field
1414
optional: bool,
1515
},
16-
/// 'category_id' is not specified
16+
/// `category_id` is not specified
1717
NotSpecified,
1818
}
1919

rust/signed_doc/src/validator/rules/content_encoding.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ pub(crate) struct ContentEncodingRule {
1212

1313
impl ContentEncodingRule {
1414
/// Field validation rule
15+
#[allow(clippy::unused_async)]
1516
pub(crate) async fn check(&self, doc: &CatalystSignedDocument) -> anyhow::Result<bool> {
1617
if let Some(content_encoding) = doc.doc_content_encoding() {
1718
if content_encoding != self.exp {

rust/signed_doc/src/validator/rules/content_type.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ pub(crate) struct ContentTypeRule {
1111

1212
impl ContentTypeRule {
1313
/// Field validation rule
14+
#[allow(clippy::unused_async)]
1415
pub(crate) async fn check(&self, doc: &CatalystSignedDocument) -> anyhow::Result<bool> {
1516
let content_type = doc.doc_content_type()?;
1617
if content_type != self.exp {

0 commit comments

Comments
 (0)