diff --git a/src/addressing.rs b/src/addressing.rs index 24b16ad..1e9b8ca 100644 --- a/src/addressing.rs +++ b/src/addressing.rs @@ -30,14 +30,14 @@ impl Address { }; let mut result = Cursor::new(vec![0u8; 0]); - result.write(encode::u128(hash_func_type, &mut encode::u128_buffer()))?; - result.write(encode::usize(digest.len(), &mut encode::usize_buffer()))?; - result.write(digest.as_slice())?; + result.write_all(encode::u128(hash_func_type, &mut encode::u128_buffer()))?; + result.write_all(encode::usize(digest.len(), &mut encode::usize_buffer()))?; + result.write_all(digest.as_slice())?; Ok(result.get_ref().clone()) } - pub fn decode(buffer: &Vec) -> Result { + pub fn decode(buffer: &[u8]) -> Result { let (hash_func_type, rest) = unsigned_varint::decode::u128(buffer)?; let (digest_len, rest) = unsigned_varint::decode::usize(rest)?; let digest = rest; diff --git a/src/database.rs b/src/database.rs index a0476d1..81b701a 100644 --- a/src/database.rs +++ b/src/database.rs @@ -74,9 +74,9 @@ impl std::fmt::Display for InnerEntry { impl Hashable for InnerEntry { fn hash(self: &InnerEntry) -> Result { let mut result = Cursor::new(vec![0u8; 0]); - result.write(self.target.encode()?.as_slice())?; - result.write(self.key.as_bytes())?; - result.write(self.value.to_str()?.as_bytes())?; + result.write_all(self.target.encode()?.as_slice())?; + result.write_all(self.key.as_bytes())?; + result.write_all(self.value.to_str()?.as_bytes())?; Ok(hash(result.get_ref())) } } @@ -115,17 +115,15 @@ impl std::str::FromStr for EntryValue { let (type_char, content) = s.split_at(1); match (type_char, content) { ("J", content) => { - let value = serde_json::from_str(content); - if value.is_ok() { - Ok(EntryValue::Value(value.unwrap())) + if let Ok(value) = serde_json::from_str(content) { + Ok(EntryValue::Value(value)) } else { Ok(EntryValue::Invalid) } } ("O", content) => { - let addr = decode(content).and_then(|v| Address::decode(&v)); - if addr.is_ok() { - Ok(EntryValue::Address(addr.unwrap())) + if let Ok(addr) = decode(content).and_then(|v| Address::decode(&v)) { + Ok(EntryValue::Address(addr)) } else { Ok(EntryValue::Invalid) } @@ -232,7 +230,7 @@ impl Handler for DbExecutor { let matches = data .filter(target.eq(msg.target.encode()?)) - .or_filter(value.eq(EntryValue::Address(msg.target.clone()).to_str()?)) + .or_filter(value.eq(EntryValue::Address(msg.target).to_str()?)) .load::(connection)?; let entries = matches .into_iter() diff --git a/src/filesystem.rs b/src/filesystem.rs index 99eae3d..b048a2f 100644 --- a/src/filesystem.rs +++ b/src/filesystem.rs @@ -36,7 +36,7 @@ impl std::str::FromStr for UPath { type Err = anyhow::Error; fn from_str(string: &str) -> Result { - if string.len() == 0 { + if string.is_empty() { Ok(UPath(vec![])) } else { let result = match string.find(TOP_SEPARATOR) { @@ -49,7 +49,7 @@ impl std::str::FromStr for UPath { result.append( rest[TOP_SEPARATOR.len()..rest.len()] .trim_end_matches('/') - .split("/") + .split('/') .map(|part| UDirectory { name: String::from(part), }) @@ -61,7 +61,7 @@ impl std::str::FromStr for UPath { } None => string .trim_end_matches('/') - .split("/") + .split('/') .map(|part| UDirectory { name: String::from(part), }) @@ -69,7 +69,7 @@ impl std::str::FromStr for UPath { }; for directory in &result { - if directory.name.len() == 0 { + if directory.name.is_empty() { return Err(anyhow!("INVALID PATH: Directory name cannot be empty!")); } } @@ -112,7 +112,7 @@ trait EntryList { impl EntryList for Vec { fn extract_addresses(&self) -> Vec
{ - self.into_iter() + self.iter() .filter_map(|e| { if let EntryValue::Address(address) = &e.value { Some(address.clone()) @@ -218,12 +218,10 @@ pub async fn fetch_or_create_dir( .await?? .extract_addresses(); - let valid = directories + directories .into_iter() .filter(|a| parent_has.contains(a)) - .collect(); - - valid + .collect() } None => directories, }; @@ -273,7 +271,7 @@ pub async fn resolve_path( let mut path_stack = path.0.to_vec(); path_stack.reverse(); - while path_stack.len() > 0 { + while !path_stack.is_empty() { let dir_address = fetch_or_create_dir( db_executor, result.last().cloned(), diff --git a/src/hash.rs b/src/hash.rs index d51756f..9100ae5 100644 --- a/src/hash.rs +++ b/src/hash.rs @@ -1,9 +1,7 @@ -use std::path::{Path, PathBuf}; - use actix::prelude::*; use anyhow::{anyhow, Result}; -use bs58; use filebuffer::FileBuffer; +use std::path::{Path, PathBuf}; use tiny_keccak::{Hasher, KangarooTwelve}; #[derive(Debug, Clone, PartialEq)]