From ea7a5e6f189aa72995207220eda3eaecafe44066 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Ml=C3=A1dek?= Date: Thu, 29 Jun 2023 15:17:06 +0200 Subject: [PATCH] wip, chore: clippy fixes --- base/src/addressing.rs | 17 ++++++++--------- base/src/entry.rs | 18 +----------------- cli/src/main.rs | 2 +- cli/src/routes.rs | 12 ++++++------ tools/upend_wasm/src/lib.rs | 3 ++- 5 files changed, 18 insertions(+), 34 deletions(-) diff --git a/base/src/addressing.rs b/base/src/addressing.rs index 611749e..e7e4a81 100644 --- a/base/src/addressing.rs +++ b/base/src/addressing.rs @@ -29,7 +29,7 @@ pub struct AddressComponents { pub c: Option, } -// multicodec RAW code +/// multicodec RAW code const RAW: u64 = 0x55; /// multicodec UpEnd UUID code (reserved area) @@ -106,7 +106,7 @@ impl Address { } } - pub fn as_components<'a>(&'a self) -> AddressComponents { + pub fn as_components(&self) -> AddressComponents { // TODO: make this automatically derive from `Address` definition let (entity_type, entity_content) = match self { Address::Hash(uphash) => ("Hash", Some(b58_encode(uphash.to_bytes()))), @@ -124,12 +124,11 @@ impl Address { pub fn from_components(components: AddressComponents) -> Result { // TODO: make this automatically derive from `Address` definition let address = match components { - AddressComponents { t, c } if t == "Attribute" => Address::Attribute( - c.map(|x| x.to_string()) - .ok_or(UpEndError::AddressComponentsDecodeError( - AddressComponentsDecodeError::MissingValue, - ))?, - ), + AddressComponents { t, c } if t == "Attribute" => { + Address::Attribute(c.ok_or(UpEndError::AddressComponentsDecodeError( + AddressComponentsDecodeError::MissingValue, + ))?) + } AddressComponents { t, c } if t == "Url" => Address::Url(if let Some(string) = c { Url::parse(&string).map_err(|e| { UpEndError::AddressComponentsDecodeError( @@ -251,7 +250,7 @@ mod tests { #[test] fn test_hash_codec() -> Result<(), UpEndError> { let addr = Address::Hash(UpMultihash::from( - LargeMultihash::wrap(IDENTITY, &vec![1, 2, 3, 4, 5]).unwrap(), + LargeMultihash::wrap(IDENTITY, &[1, 2, 3, 4, 5]).unwrap(), )); let encoded = addr.encode()?; let decoded = Address::decode(&encoded)?; diff --git a/base/src/entry.rs b/base/src/entry.rs index 9b15776..b902182 100644 --- a/base/src/entry.rs +++ b/base/src/entry.rs @@ -70,22 +70,6 @@ impl std::fmt::Display for Entry { } } -// impl Hashable for Entry { -// fn hash(self: &Entry) -> Result { -// let mut result = Cursor::new(vec![0u8; 0]); -// result.write_all(self.entity.encode()?.as_slice())?; -// result.write_all(self.attribute.as_bytes())?; -// result.write_all(self.value.to_string()?.as_bytes())?; -// Ok(hash(result.get_ref())) -// } -// } - -// impl Hashable for InvariantEntry { -// fn hash(&self) -> Result { -// Entry::try_from(self)?.hash() -// } -// } - impl AsMultihash for Entry { fn as_multihash(&self) -> Result { let mut result = Cursor::new(vec![0u8; 0]); @@ -102,7 +86,7 @@ impl AsMultihash for Entry { .map_err(|e| AsMultihashError(e.to_string()))? .as_bytes(), )?; - Ok(sha256hash(result.get_ref())?) + sha256hash(result.get_ref()) } } diff --git a/cli/src/main.rs b/cli/src/main.rs index cd744c7..0ea7a21 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -307,7 +307,7 @@ async fn main() -> Result<()> { AddressType::File => hash_path(&input)?, AddressType::Sha256sum => { let digest = multibase::Base::Base16Lower.decode(input)?; - Address::Hash(UpMultihash::from_sha256(&digest).unwrap()) + Address::Hash(UpMultihash::from_sha256(digest).unwrap()) } }; diff --git a/cli/src/routes.rs b/cli/src/routes.rs index 473bc36..49c9830 100644 --- a/cli/src/routes.rs +++ b/cli/src/routes.rs @@ -1010,11 +1010,11 @@ mod tests { >(None, vec![], get_state())) .await; - let digest = UpMultihash::from_sha256(&vec![1, 2, 3, 4, 5]).unwrap(); - let digest_str = b58_encode(&digest.to_bytes()); + let digest = UpMultihash::from_sha256([1, 2, 3, 4, 5]).unwrap(); + let digest_str = b58_encode(digest.to_bytes()); let address = Address::Hash(digest); let req = actix_web::test::TestRequest::get() - .uri(&format!("/api/obj/{}", address.to_string())) + .uri(&format!("/api/obj/{}", address)) .to_request(); let result: serde_json::Value = actix_web::test::call_and_read_body_json(&app, req).await; @@ -1023,7 +1023,7 @@ mod tests { let address = Address::Attribute("TEST".to_string()); let req = actix_web::test::TestRequest::get() - .uri(&format!("/api/obj/{}", address.to_string())) + .uri(&format!("/api/obj/{}", address)) .to_request(); let result: serde_json::Value = actix_web::test::call_and_read_body_json(&app, req).await; @@ -1032,7 +1032,7 @@ mod tests { let address = Address::Url("https://upend.dev/".parse().unwrap()); let req = actix_web::test::TestRequest::get() - .uri(&format!("/api/obj/{}", address.to_string())) + .uri(&format!("/api/obj/{}", address)) .to_request(); let result: serde_json::Value = actix_web::test::call_and_read_body_json(&app, req).await; @@ -1042,7 +1042,7 @@ mod tests { let uuid = uuid::Uuid::new_v4(); let address = Address::Uuid(uuid); let req = actix_web::test::TestRequest::get() - .uri(&format!("/api/obj/{}", address.to_string())) + .uri(&format!("/api/obj/{}", address)) .to_request(); let result: serde_json::Value = actix_web::test::call_and_read_body_json(&app, req).await; diff --git a/tools/upend_wasm/src/lib.rs b/tools/upend_wasm/src/lib.rs index 8d3a11e..df8a844 100644 --- a/tools/upend_wasm/src/lib.rs +++ b/tools/upend_wasm/src/lib.rs @@ -19,6 +19,7 @@ impl std::fmt::Display for WasmError { impl std::error::Error for WasmError {} +#[allow(clippy::from_over_into)] impl Into for WasmError { fn into(self) -> JsValue { JsValue::from_str(&self.0) @@ -46,7 +47,7 @@ pub fn components_to_addr(components: AddressComponents) -> Result Self {