clippy fixes
This commit is contained in:
parent
a65e485aed
commit
01a737285c
4 changed files with 21 additions and 27 deletions
|
@ -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<u8>) -> Result<Self> {
|
||||
pub fn decode(buffer: &[u8]) -> Result<Self> {
|
||||
let (hash_func_type, rest) = unsigned_varint::decode::u128(buffer)?;
|
||||
let (digest_len, rest) = unsigned_varint::decode::usize(rest)?;
|
||||
let digest = rest;
|
||||
|
|
|
@ -74,9 +74,9 @@ impl std::fmt::Display for InnerEntry {
|
|||
impl Hashable for InnerEntry {
|
||||
fn hash(self: &InnerEntry) -> Result<Hash> {
|
||||
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<RetrieveObject> 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::<models::Entry>(connection)?;
|
||||
let entries = matches
|
||||
.into_iter()
|
||||
|
|
|
@ -36,7 +36,7 @@ impl std::str::FromStr for UPath {
|
|||
type Err = anyhow::Error;
|
||||
|
||||
fn from_str(string: &str) -> Result<Self, Self::Err> {
|
||||
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<Entry> {
|
||||
fn extract_addresses(&self) -> Vec<Address> {
|
||||
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(),
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in a new issue