Fix clippyisms

This commit is contained in:
Tony Garnock-Jones 2019-10-20 14:02:51 +01:00
parent 408c9feda9
commit e3b8ff02fc
3 changed files with 13 additions and 7 deletions

View File

@ -13,11 +13,17 @@ pub enum Net {
}
// Allows negative counts - a "delta"
pub struct BTreeBag<V> where V: std::cmp::Ord {
pub struct BTreeBag<V: std::cmp::Ord> {
counts: BTreeMap<V, Count>,
}
impl<V> BTreeBag<V> where V: std::cmp::Ord {
impl<V: std::cmp::Ord> std::default::Default for BTreeBag<V> {
fn default() -> Self {
Self::new()
}
}
impl<V: std::cmp::Ord> BTreeBag<V> {
pub fn new() -> BTreeBag<V> {
BTreeBag { counts: BTreeMap::new() }
}
@ -59,7 +65,7 @@ impl<V> BTreeBag<V> where V: std::cmp::Ord {
}
}
impl<'a, V> IntoIterator for &'a BTreeBag<V> where V: std::cmp::Ord {
impl<'a, V: std::cmp::Ord> IntoIterator for &'a BTreeBag<V> {
type Item = (&'a V, &'a Count);
type IntoIter = Iter<'a, V, Count>;
@ -68,7 +74,7 @@ impl<'a, V> IntoIterator for &'a BTreeBag<V> where V: std::cmp::Ord {
}
}
impl<V> FromIterator<V> for BTreeBag<V> where V: std::cmp::Ord {
impl<V: std::cmp::Ord> FromIterator<V> for BTreeBag<V> {
fn from_iter<I: IntoIterator<Item=V>>(iter: I) -> Self {
let mut bag = Self::new();
for k in iter {
@ -78,7 +84,7 @@ impl<V> FromIterator<V> for BTreeBag<V> where V: std::cmp::Ord {
}
}
impl<V> std::ops::Index<&V> for BTreeBag<V> where V: std::cmp::Ord {
impl<V: std::cmp::Ord> std::ops::Index<&V> for BTreeBag<V> {
type Output = Count;
fn index(&self, i: &V) -> &Count {
self.counts.get(i).unwrap_or(&0)

View File

@ -26,7 +26,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let (stream, addr) = listener.accept().await?;
let connid = id;
let spaces = Arc::clone(&spaces);
id = id + 1;
id += 1;
tokio::spawn(async move {
match peer::Peer::new(connid, stream).await.run(spaces).await {
Ok(_) => (),

View File

@ -63,7 +63,7 @@ pub enum EncodeError {
impl From<io::Error> for EncodeError {
fn from(v: io::Error) -> Self {
EncodeError::Write(v.into())
EncodeError::Write(v)
}
}