clippy fixes

This commit is contained in:
Tomáš Mládek 2020-09-14 01:16:01 +02:00
parent a65e485aed
commit 01a737285c
4 changed files with 21 additions and 27 deletions

View file

@ -30,14 +30,14 @@ impl Address {
}; };
let mut result = Cursor::new(vec![0u8; 0]); let mut result = Cursor::new(vec![0u8; 0]);
result.write(encode::u128(hash_func_type, &mut encode::u128_buffer()))?; result.write_all(encode::u128(hash_func_type, &mut encode::u128_buffer()))?;
result.write(encode::usize(digest.len(), &mut encode::usize_buffer()))?; result.write_all(encode::usize(digest.len(), &mut encode::usize_buffer()))?;
result.write(digest.as_slice())?; result.write_all(digest.as_slice())?;
Ok(result.get_ref().clone()) Ok(result.get_ref().clone())
} }
pub fn decode(buffer: &Vec<u8>) -> Result<Self> { pub fn decode(buffer: &[u8]) -> Result<Self> {
let (hash_func_type, rest) = unsigned_varint::decode::u128(buffer)?; let (hash_func_type, rest) = unsigned_varint::decode::u128(buffer)?;
let (digest_len, rest) = unsigned_varint::decode::usize(rest)?; let (digest_len, rest) = unsigned_varint::decode::usize(rest)?;
let digest = rest; let digest = rest;

View file

@ -74,9 +74,9 @@ impl std::fmt::Display for InnerEntry {
impl Hashable for InnerEntry { impl Hashable for InnerEntry {
fn hash(self: &InnerEntry) -> Result<Hash> { fn hash(self: &InnerEntry) -> Result<Hash> {
let mut result = Cursor::new(vec![0u8; 0]); let mut result = Cursor::new(vec![0u8; 0]);
result.write(self.target.encode()?.as_slice())?; result.write_all(self.target.encode()?.as_slice())?;
result.write(self.key.as_bytes())?; result.write_all(self.key.as_bytes())?;
result.write(self.value.to_str()?.as_bytes())?; result.write_all(self.value.to_str()?.as_bytes())?;
Ok(hash(result.get_ref())) Ok(hash(result.get_ref()))
} }
} }
@ -115,17 +115,15 @@ impl std::str::FromStr for EntryValue {
let (type_char, content) = s.split_at(1); let (type_char, content) = s.split_at(1);
match (type_char, content) { match (type_char, content) {
("J", content) => { ("J", content) => {
let value = serde_json::from_str(content); if let Ok(value) = serde_json::from_str(content) {
if value.is_ok() { Ok(EntryValue::Value(value))
Ok(EntryValue::Value(value.unwrap()))
} else { } else {
Ok(EntryValue::Invalid) Ok(EntryValue::Invalid)
} }
} }
("O", content) => { ("O", content) => {
let addr = decode(content).and_then(|v| Address::decode(&v)); if let Ok(addr) = decode(content).and_then(|v| Address::decode(&v)) {
if addr.is_ok() { Ok(EntryValue::Address(addr))
Ok(EntryValue::Address(addr.unwrap()))
} else { } else {
Ok(EntryValue::Invalid) Ok(EntryValue::Invalid)
} }
@ -232,7 +230,7 @@ impl Handler<RetrieveObject> for DbExecutor {
let matches = data let matches = data
.filter(target.eq(msg.target.encode()?)) .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::<models::Entry>(connection)?; .load::<models::Entry>(connection)?;
let entries = matches let entries = matches
.into_iter() .into_iter()

View file

@ -36,7 +36,7 @@ impl std::str::FromStr for UPath {
type Err = anyhow::Error; type Err = anyhow::Error;
fn from_str(string: &str) -> Result<Self, Self::Err> { fn from_str(string: &str) -> Result<Self, Self::Err> {
if string.len() == 0 { if string.is_empty() {
Ok(UPath(vec![])) Ok(UPath(vec![]))
} else { } else {
let result = match string.find(TOP_SEPARATOR) { let result = match string.find(TOP_SEPARATOR) {
@ -49,7 +49,7 @@ impl std::str::FromStr for UPath {
result.append( result.append(
rest[TOP_SEPARATOR.len()..rest.len()] rest[TOP_SEPARATOR.len()..rest.len()]
.trim_end_matches('/') .trim_end_matches('/')
.split("/") .split('/')
.map(|part| UDirectory { .map(|part| UDirectory {
name: String::from(part), name: String::from(part),
}) })
@ -61,7 +61,7 @@ impl std::str::FromStr for UPath {
} }
None => string None => string
.trim_end_matches('/') .trim_end_matches('/')
.split("/") .split('/')
.map(|part| UDirectory { .map(|part| UDirectory {
name: String::from(part), name: String::from(part),
}) })
@ -69,7 +69,7 @@ impl std::str::FromStr for UPath {
}; };
for directory in &result { for directory in &result {
if directory.name.len() == 0 { if directory.name.is_empty() {
return Err(anyhow!("INVALID PATH: Directory name cannot be empty!")); return Err(anyhow!("INVALID PATH: Directory name cannot be empty!"));
} }
} }
@ -112,7 +112,7 @@ trait EntryList {
impl EntryList for Vec<Entry> { impl EntryList for Vec<Entry> {
fn extract_addresses(&self) -> Vec<Address> { fn extract_addresses(&self) -> Vec<Address> {
self.into_iter() self.iter()
.filter_map(|e| { .filter_map(|e| {
if let EntryValue::Address(address) = &e.value { if let EntryValue::Address(address) = &e.value {
Some(address.clone()) Some(address.clone())
@ -218,12 +218,10 @@ pub async fn fetch_or_create_dir(
.await?? .await??
.extract_addresses(); .extract_addresses();
let valid = directories directories
.into_iter() .into_iter()
.filter(|a| parent_has.contains(a)) .filter(|a| parent_has.contains(a))
.collect(); .collect()
valid
} }
None => directories, None => directories,
}; };
@ -273,7 +271,7 @@ pub async fn resolve_path(
let mut path_stack = path.0.to_vec(); let mut path_stack = path.0.to_vec();
path_stack.reverse(); path_stack.reverse();
while path_stack.len() > 0 { while !path_stack.is_empty() {
let dir_address = fetch_or_create_dir( let dir_address = fetch_or_create_dir(
db_executor, db_executor,
result.last().cloned(), result.last().cloned(),

View file

@ -1,9 +1,7 @@
use std::path::{Path, PathBuf};
use actix::prelude::*; use actix::prelude::*;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use bs58;
use filebuffer::FileBuffer; use filebuffer::FileBuffer;
use std::path::{Path, PathBuf};
use tiny_keccak::{Hasher, KangarooTwelve}; use tiny_keccak::{Hasher, KangarooTwelve};
#[derive(Debug, Clone, PartialEq)] #[derive(Debug, Clone, PartialEq)]