Skip to content

Commit

Permalink
clippied
Browse files Browse the repository at this point in the history
  • Loading branch information
jbr committed Jun 25, 2020
1 parent bbb7893 commit 089e996
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
21 changes: 1 addition & 20 deletions src/listener/multi_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use async_std::prelude::*;
///}
///```

#[derive(Default)]
pub struct MultiListener<State>(Vec<Box<dyn Listener<State>>>);

impl<State: Send + Sync + 'static> MultiListener<State> {
Expand Down Expand Up @@ -75,26 +76,6 @@ impl<State: Send + Sync + 'static> MultiListener<State> {
self.add(listener).expect("Unable to add listener");
self
}

/// from_iter allows for the construction of a new MultiListener
/// from collections of [`ToListener`](ToListener)s.
/// ```rust
/// # use tide::listener::MultiListener;
/// # fn main() -> std::io::Result<()> {
/// let mut multi = MultiListener::from_iter(vec!["127.0.0.1:8000", "tcp://localhost:8001"])?;
/// if cfg!(unix) {
/// multi.add("unix:///var/run/tide/socket")?;
/// }
/// # std::mem::drop(tide::new().listen(multi)); // for the State generic
/// # Ok(()) }
/// ```
pub fn from_iter<TL: ToListener<State>>(vec: impl IntoIterator<Item = TL>) -> io::Result<Self> {
let mut multi = Self::new();
for listener in vec {
multi.add(listener)?;
}
Ok(multi)
}
}

impl<State: Send + Sync + 'static> Listener<State> for MultiListener<State> {
Expand Down
10 changes: 7 additions & 3 deletions src/listener/to_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ impl<State: Send + Sync + 'static> ToListener<State> for Url {
self.path()
));

return Ok(ParsedListener::Unix(UnixListener::from_path(path)));
Ok(ParsedListener::Unix(UnixListener::from_path(path)))
}

#[cfg(not(unix))]
Expand Down Expand Up @@ -132,7 +132,7 @@ impl<State: Send + Sync + 'static> ToListener<State> for &str {
format!("unable to parse listener from `{}`", self),
)
})
.and_then(|url| ToListener::<State>::to_listener(url))
.and_then(ToListener::<State>::to_listener)
})
}
}
Expand Down Expand Up @@ -230,7 +230,11 @@ impl<State: Send + Sync + 'static> ToListener<State> for std::net::SocketAddr {
impl<TL: ToListener<State>, State: Send + Sync + 'static> ToListener<State> for Vec<TL> {
type Listener = MultiListener<State>;
fn to_listener(self) -> io::Result<Self::Listener> {
MultiListener::from_iter(self)
let mut multi = MultiListener::new();
for listener in self {
multi.add(listener)?;
}
Ok(multi)
}
}

Expand Down

0 comments on commit 089e996

Please sign in to comment.