wip, chore: clippy fixes
ci/woodpecker/push/woodpecker Pipeline failed Details

feat/type-attributes
Tomáš Mládek 2023-06-29 15:17:06 +02:00
parent 0a27931de4
commit ea7a5e6f18
5 changed files with 18 additions and 34 deletions

View File

@ -29,7 +29,7 @@ pub struct AddressComponents {
pub c: Option<String>,
}
// 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<Self, UpEndError> {
// 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)?;

View File

@ -70,22 +70,6 @@ impl std::fmt::Display for Entry {
}
}
// impl Hashable for Entry {
// fn hash(self: &Entry) -> Result<Hash> {
// 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<Hash> {
// Entry::try_from(self)?.hash()
// }
// }
impl AsMultihash for Entry {
fn as_multihash(&self) -> Result<UpMultihash, AsMultihashError> {
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())
}
}

View File

@ -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())
}
};

View File

@ -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;

View File

@ -19,6 +19,7 @@ impl std::fmt::Display for WasmError {
impl std::error::Error for WasmError {}
#[allow(clippy::from_over_into)]
impl Into<JsValue> for WasmError {
fn into(self) -> JsValue {
JsValue::from_str(&self.0)
@ -46,7 +47,7 @@ pub fn components_to_addr(components: AddressComponents) -> Result<String, WasmE
pub struct AddressTypeConstants {}
#[wasm_bindgen]
#[allow(non_snake_case)]
#[allow(non_snake_case, clippy::new_without_default)]
impl AddressTypeConstants {
#[wasm_bindgen(constructor)]
pub fn new() -> Self {