src/server/rest.rs: avoid unwrap
This commit is contained in:
parent
7fb4f5642a
commit
80af046794
@ -49,10 +49,16 @@ impl MakeService<&tokio_openssl::SslStream<tokio::net::TcpStream>> for RestServe
|
||||
type Service = ApiService;
|
||||
type Future = Box<dyn Future<Item = Self::Service, Error = Self::MakeError> + Send>;
|
||||
fn make_service(&mut self, ctx: &tokio_openssl::SslStream<tokio::net::TcpStream>) -> Self::Future {
|
||||
let peer = ctx.get_ref().get_ref().peer_addr().unwrap();
|
||||
match ctx.get_ref().get_ref().peer_addr() {
|
||||
Err(err) => {
|
||||
Box::new(future::err(format_err!("unable to get peer address - {}", err)))
|
||||
}
|
||||
Ok(peer) => {
|
||||
Box::new(future::ok(ApiService { peer, api_config: self.api_config.clone() }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MakeService<&tokio::net::TcpStream> for RestServer
|
||||
{
|
||||
@ -63,10 +69,16 @@ impl MakeService<&tokio::net::TcpStream> for RestServer
|
||||
type Service = ApiService;
|
||||
type Future = Box<dyn Future<Item = Self::Service, Error = Self::MakeError> + Send>;
|
||||
fn make_service(&mut self, ctx: &tokio::net::TcpStream) -> Self::Future {
|
||||
let peer = ctx.peer_addr().unwrap();
|
||||
match ctx.peer_addr() {
|
||||
Err(err) => {
|
||||
Box::new(future::err(format_err!("unable to get peer address - {}", err)))
|
||||
}
|
||||
Ok(peer) => {
|
||||
Box::new(future::ok(ApiService { peer, api_config: self.api_config.clone() }))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub struct ApiService {
|
||||
|
Loading…
Reference in New Issue
Block a user