From 5700a5e1e052825019df2ba996c3d6dd59388338 Mon Sep 17 00:00:00 2001 From: pasberth Date: Fri, 25 Jan 2019 17:07:19 +0900 Subject: [PATCH] improve Read implementation --- .circleci/config.yml | 5 +- examples/attach-container.rs | 2 +- examples/build-image.rs | 7 +- examples/containers.rs | 2 +- examples/history.rs | 8 +- examples/prune-image.rs | 2 +- examples/push.rs | 5 +- src/container.rs | 4 +- src/credentials.rs | 3 +- src/docker.rs | 169 +++++++++++++++-------------------- src/errors.rs | 4 +- src/header.rs | 8 +- src/http_client.rs | 2 +- src/hyper_client.rs | 161 +++++++++++++++++++++++---------- src/lib.rs | 8 +- src/options.rs | 2 +- src/response.rs | 5 +- src/test.rs | 6 +- 18 files changed, 228 insertions(+), 175 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 673c8cf..3774e68 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -49,9 +49,12 @@ jobs: apt list --installed >> /tmp/build-dep - restore_cache: key: cache-cargo-target-{{ .Environment.CIRCLE_JOB }}-{{ .Environment.CIRCLECI_CACHE_VERSION }}-{{ checksum "/tmp/build-dep" }} + - run: + name: Install rustfmt + command: rustup component add rustfmt-preview - run: name: Checking source code style - command: cargo fmt -- --write-mode "diff" + command: cargo fmt -- --check - run: name: Build project command: | diff --git a/examples/attach-container.rs b/examples/attach-container.rs index 50aec7a..31aee6a 100644 --- a/examples/attach-container.rs +++ b/examples/attach-container.rs @@ -1,7 +1,7 @@ extern crate dockworker; extern crate hyper; -use dockworker::{ContainerCreateOptions, ContainerHostConfig, Docker, container::AttachContainer}; +use dockworker::{container::AttachContainer, ContainerCreateOptions, ContainerHostConfig, Docker}; use std::io::{BufRead, BufReader}; fn main() { diff --git a/examples/build-image.rs b/examples/build-image.rs index 68f6154..b3b023f 100644 --- a/examples/build-image.rs +++ b/examples/build-image.rs @@ -1,11 +1,11 @@ extern crate dockworker; extern crate tar; +use dockworker::{ContainerBuildOptions, Docker}; +use std::fs::File; use std::io::{BufRead, BufReader, Write}; use std::path::Path; -use std::fs::File; use tar::Builder; -use dockworker::{ContainerBuildOptions, Docker}; fn main() { { @@ -14,7 +14,8 @@ fn main() { .write_all( r#"FROM alpine:edge RUN echo Hi mum - "#.as_bytes(), + "# + .as_bytes(), ) .unwrap(); } diff --git a/examples/containers.rs b/examples/containers.rs index 7d38c9e..05d0895 100644 --- a/examples/containers.rs +++ b/examples/containers.rs @@ -1,6 +1,6 @@ extern crate dockworker; -use dockworker::{Docker, container::ContainerFilters}; +use dockworker::{container::ContainerFilters, Docker}; fn main() { let docker = Docker::connect_with_defaults().unwrap(); diff --git a/examples/history.rs b/examples/history.rs index aa78adc..080f773 100644 --- a/examples/history.rs +++ b/examples/history.rs @@ -8,9 +8,11 @@ fn main() { println!("History:"); match history { - Ok(changes) => for change in changes { - println!("{:#?}", change); - }, + Ok(changes) => { + for change in changes { + println!("{:#?}", change); + } + } Err(e) => { println!("Error {}", e); } diff --git a/examples/prune-image.rs b/examples/prune-image.rs index bafda41..57bed3b 100644 --- a/examples/prune-image.rs +++ b/examples/prune-image.rs @@ -1,6 +1,6 @@ extern crate dockworker; -use dockworker::{Docker, container::ContainerFilters}; +use dockworker::{container::ContainerFilters, Docker}; fn main() { let docker = Docker::connect_with_defaults().unwrap(); diff --git a/examples/push.rs b/examples/push.rs index f1d063b..54b39d9 100644 --- a/examples/push.rs +++ b/examples/push.rs @@ -1,7 +1,10 @@ extern crate dockworker; extern crate hyper; -use dockworker::{Docker, credentials::{Credential, UserPassword}}; +use dockworker::{ + credentials::{Credential, UserPassword}, + Docker, +}; fn main() { let mut docker = Docker::connect_with_defaults().unwrap(); diff --git a/src/container.rs b/src/container.rs index 03fb0a4..a82116f 100644 --- a/src/container.rs +++ b/src/container.rs @@ -1,11 +1,11 @@ use byteorder::{BigEndian, ReadBytesExt}; +use errors::Result; use hyper_client::Response; use std; +use std::cell::{Ref, RefCell, RefMut}; use std::collections::HashMap; use std::io::{self, Read}; use std::rc::Rc; -use std::cell::{Ref, RefCell, RefMut}; -use errors::Result; #[derive(Debug, Clone, Serialize, Deserialize)] #[allow(non_snake_case)] diff --git a/src/credentials.rs b/src/credentials.rs index 2ee5383..fbfd848 100644 --- a/src/credentials.rs +++ b/src/credentials.rs @@ -1,9 +1,8 @@ +use header::XRegistryAuth; ///! Access credentials for accessing any docker daemon endpoints ///! ///! Currently, any values of these types are only used for `/images/{name}/push` api. - use serde_json; -use header::XRegistryAuth; use system::AuthToken; /// Access credential diff --git a/src/docker.rs b/src/docker.rs index c2798f9..9908dcf 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -8,8 +8,10 @@ use std::result; use std::time::Duration; use url; -use container::{AttachResponse, Container, ContainerFilters, ContainerInfo, ExecInfo, ExitStatus, - LogResponse}; +use container::{ + AttachResponse, Container, ContainerFilters, ContainerInfo, ExecInfo, ExitStatus, LogResponse, +}; +pub use credentials::{Credential, UserPassword}; use errors::*; use filesystem::FilesystemChange; use hyper_client::HyperClient; @@ -20,16 +22,15 @@ use stats::StatsReader; use system::{AuthToken, SystemInfo}; use tar::{self, Archive}; use version::Version; -pub use credentials::{Credential, UserPassword}; -use serde::de::DeserializeOwned; -use serde_json; -use signal::Signal; use header::XRegistryAuth; use http_client::{HaveHttpClient, HttpClient}; use hyper_client::{ContentType, Headers, Response, StatusCode}; use mime; use response::Response as DockerResponse; +use serde::de::DeserializeOwned; +use serde_json; +use signal::Signal; /// The default `DOCKER_HOST` address that we will try to connect to. #[cfg(unix)] @@ -169,7 +170,8 @@ impl Docker { &cert_path.join("key.pem"), &cert_path.join("cert.pem"), &cert_path.join("ca.pem"), - ).chain_err(&mkerr) + ) + .chain_err(&mkerr) } else { Docker::connect_with_http(&host).chain_err(&mkerr) } @@ -456,7 +458,8 @@ impl Docker { pub fn processes(&self, container: &Container) -> Result> { let top = self.container_top(container)?; - Ok(top.Processes + Ok(top + .Processes .iter() .map(|process| { let mut p = Process::default(); @@ -773,9 +776,11 @@ impl Docker { let mut headers = self.headers().clone(); let application_tar: mime::Mime = "application/x-tar".parse()?; headers.set::(ContentType(application_tar)); - let res = - self.http_client() - .post_file(&headers, &format!("/images/load?quiet={}", quiet), path)?; + let res = self.http_client().post_file( + &headers, + &format!("/images/load?quiet={}", quiet), + path, + )?; if !res.status.is_success() { return Err(serde_json::from_reader::<_, DockerError>(res)?.into()); } @@ -791,7 +796,8 @@ impl Docker { // looking for file name like XXXXXXXXXXXXXX.json if path.extension() == Some(OsStr::new("json")) && path != Path::new("manifest.json") { let stem = path.file_stem().unwrap(); // contains .json - let id = stem.to_str() + let id = stem + .to_str() .ok_or(ErrorKind::Unknown(format!("convert to String: {:?}", stem)))?; return Ok(ImageId::new(id.to_string())); } @@ -963,12 +969,12 @@ mod tests { extern crate rand; use super::*; + use std::convert::From; + use std::env; use std::fs::{remove_file, File}; use std::io::{self, Read, Write}; use std::iter::{self, Iterator}; use std::path::PathBuf; - use std::env; - use std::convert::From; use self::rand::Rng; use tar::Builder as TarBuilder; @@ -1007,53 +1013,41 @@ mod tests { .create_image(name, tag) .map(|sts| sts.for_each(|st| assert!(st.is_ok()))); assert!(sts.is_ok()); - assert!( - docker - .remove_image(&format!("{}:{}", name, tag), None, None) - .is_ok() - ); + assert!(docker + .remove_image(&format!("{}:{}", name, tag), None, None) + .is_ok()); } #[test] fn create_remove_container() { let docker = Docker::connect_with_defaults().unwrap(); let (name, tag) = ("hello-world", "linux"); - assert!( - docker - .create_image(name, tag) - .map(|sts| sts.for_each(|st| println!("{:?}", st))) - .is_ok() - ); + assert!(docker + .create_image(name, tag) + .map(|sts| sts.for_each(|st| println!("{:?}", st))) + .is_ok()); let mut create = ContainerCreateOptions::new(&format!("{}:{}", name, tag)); create.host_config(ContainerHostConfig::new()); - assert!( - docker - .create_container(Some("dockworker_test"), &create) - .is_ok() - ); - assert!( - docker - .remove_container("dockworker_test", None, None, None) - .is_ok() - ); - assert!( - docker - .remove_image(&format!("{}:{}", name, tag), None, None) - .is_ok() - ); + assert!(docker + .create_container(Some("dockworker_test"), &create) + .is_ok()); + assert!(docker + .remove_container("dockworker_test", None, None, None) + .is_ok()); + assert!(docker + .remove_image(&format!("{}:{}", name, tag), None, None) + .is_ok()); } #[test] fn auto_remove_container() { let docker = Docker::connect_with_defaults().unwrap(); let (name, tag) = ("alpine", "3.7"); - assert!( - docker - .create_image(name, tag) - .map(|sts| sts.for_each(|st| println!("{:?}", st))) - .is_ok() - ); + assert!(docker + .create_image(name, tag) + .map(|sts| sts.for_each(|st| println!("{:?}", st))) + .is_ok()); let mut host_config = ContainerHostConfig::new(); host_config.auto_remove(true); let mut create = ContainerCreateOptions::new(&format!("{}:{}", name, tag)); @@ -1069,20 +1063,16 @@ mod tests { .remove_container("dockworker_auto_remove_container", None, None, None) .is_err() // 'no such container' or 'removel container in progress' ); - assert!( - docker - .remove_image(&format!("{}:{}", name, tag), Some(true), None) - .is_ok() - ); + assert!(docker + .remove_image(&format!("{}:{}", name, tag), Some(true), None) + .is_ok()); } fn pull_image(docker: &Docker, name: &str, tag: &str) { - assert!( - docker - .create_image(name, tag) - .map(|sts| sts.for_each(|st| println!("{:?}", st))) - .is_ok() - ); + assert!(docker + .create_image(name, tag) + .map(|sts| sts.for_each(|st| println!("{:?}", st))) + .is_ok()); } #[test] @@ -1097,11 +1087,9 @@ mod tests { } assert!(docker.remove_image("alpine:latest", None, None).is_ok()); - assert!( - docker - .load_image(false, Path::new("dockworker_test_alpine.tar")) - .is_ok() - ); + assert!(docker + .load_image(false, Path::new("dockworker_test_alpine.tar")) + .is_ok()); assert!(remove_file("dockworker_test_alpine.tar").is_ok()); } @@ -1111,11 +1099,9 @@ mod tests { { pull_image(&docker, name, tag); f(name, tag); - assert!( - docker - .remove_image(&format!("{}:{}", name, tag), None, None) - .is_ok() - ); + assert!(docker + .remove_image(&format!("{}:{}", name, tag), None, None) + .is_ok()); } #[test] @@ -1126,20 +1112,16 @@ mod tests { with_image(&docker, name, tag, |name, tag| { let mut create = ContainerCreateOptions::new(&format!("{}:{}", name, tag)); create.cmd("ls".to_string()); - assert!( - docker - .create_container(Some(container_name), &create) - .is_ok() - ); + assert!(docker + .create_container(Some(container_name), &create) + .is_ok()); assert_eq!( docker.wait_container(container_name).unwrap(), ExitStatus::new(0) ); - assert!( - docker - .remove_container(container_name, None, None, None) - .is_ok() - ); + assert!(docker + .remove_container(container_name, None, None, None) + .is_ok()); }) } @@ -1259,7 +1241,8 @@ mod tests { let container = docker.create_container(None, &create_options).unwrap(); docker.start_container(&container.id).unwrap(); let mut log = docker.log_container(&container.id, &log_options).unwrap(); - let once = log.output() + let once = log + .output() .unwrap() .replace(|c| c == '\r' || c == '\n', "") .to_owned(); @@ -1306,18 +1289,14 @@ mod tests { let exp_stdout = File::open(root.join(exps[0])).unwrap(); let exp_stderr = File::open(root.join(exps[1])).unwrap(); - assert!( - exp_stdout - .bytes() - .map(|e| e.ok()) - .eq(cont.stdout.bytes().map(|e| e.ok())) - ); - assert!( - exp_stderr - .bytes() - .map(|e| e.ok()) - .eq(cont.stderr.bytes().map(|e| e.ok())) - ); + assert!(exp_stdout + .bytes() + .map(|e| e.ok()) + .eq(cont.stdout.bytes().map(|e| e.ok()))); + assert!(exp_stderr + .bytes() + .map(|e| e.ok()) + .eq(cont.stderr.bytes().map(|e| e.ok()))); docker.wait_container(&container.id).unwrap(); docker @@ -1422,12 +1401,10 @@ mod tests { }); let stdout_buffer = BufReader::new(cont.stdout); - assert!( - stdout_buffer - .lines() - .map(|line| line.unwrap()) - .eq(signalstrs) - ); + assert!(stdout_buffer + .lines() + .map(|line| line.unwrap()) + .eq(signalstrs)); trace!("wait"); assert_eq!( diff --git a/src/errors.rs b/src/errors.rs index 52a3f6b..bff81df 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -1,13 +1,13 @@ //! Error-handling with the `error_chain` crate. +use base64; use docker; use http; use hyper; +use response; use serde_json; use std::env; use std::io; -use base64; -use response; error_chain! { foreign_links { diff --git a/src/header.rs b/src/header.rs index 7774d05..06319fd 100644 --- a/src/header.rs +++ b/src/header.rs @@ -1,10 +1,10 @@ +use base64::{self, STANDARD}; +use hyperx::header::Header; +use hyperx::Error; +use hyperx::Result; ///! HTTP header used in docker api ///! use std::fmt; -use hyperx::header::Header; -use hyperx::Result; -use hyperx::Error; -use base64::{self, STANDARD}; /// The http header represent `X-Registry-Auth` #[derive(Debug, Clone, Serialize, Deserialize)] diff --git a/src/http_client.rs b/src/http_client.rs index 871bc71..2e080b3 100644 --- a/src/http_client.rs +++ b/src/http_client.rs @@ -1,5 +1,5 @@ -use std::result; use std::path::Path; +use std::result; use hyper_client::*; diff --git a/src/hyper_client.rs b/src/hyper_client.rs index 15bd968..4d385d1 100644 --- a/src/hyper_client.rs +++ b/src/hyper_client.rs @@ -14,9 +14,9 @@ use http_client::HttpClient; use std::io::Read; use std::str::FromStr; -use tokio; use futures::future::Future; use futures::future::IntoFuture; +use tokio; #[derive(Clone, Debug)] enum Client { @@ -48,9 +48,7 @@ pub struct Response { } impl Response { - pub fn new( - mut res: http::Response, - ) -> Response { + pub fn new(mut res: http::Response) -> Response { let status = res.status(); let (tx, rx) = futures::sync::mpsc::unbounded(); @@ -100,27 +98,28 @@ impl std::io::Read for Response { .by_ref() .map(|chunk| chunk.into_bytes()) .skip_while(|bytes| { - if j <= n { - let m = std::cmp::min(bytes.len(), n - j); - j += bytes.len(); + let m = std::cmp::min(bytes.len(), n - j); + let len = bytes.len(); + j += len; - for byte in &bytes[..m] { - buf[i] = *byte; - i += 1; - } + for byte in &bytes[..m] { + buf[i] = *byte; + i += 1; + } - for byte in &bytes[m..] { - buffer.push(*byte); - } + if len < m { + return Ok(true); + } - Ok(true) - } else { - for byte in bytes.into_iter() { - buffer.push(byte); - } + if len == m { + return Ok(false); + } - Ok(false) + for byte in &bytes[m..] { + buffer.push(*byte); } + + Ok(false) }); if let Err(_) = stream.into_future().wait() { @@ -165,18 +164,33 @@ fn with_redirect( uri: Uri, headers: Headers, body: Option, - future: hyper::client::ResponseFuture -) -> Box, Error = hyper::error::Error> + Send + 'static> { - + future: hyper::client::ResponseFuture, +) -> Box< + hyper::rt::Future, Error = hyper::error::Error> + + Send + + 'static, +> { if max_redirects == 0 { - Box::new(future) as Box, Error = hyper::error::Error> + Send + 'static> + Box::new(future) + as Box< + hyper::rt::Future, Error = hyper::error::Error> + + Send + + 'static, + > } else { Box::new(future.and_then(move |res| { let mut request = request_builder(&method, &uri, &headers); let uri_parts = http::uri::Parts::from(uri.clone()); if !res.status().is_redirection() { - Box::new(Ok(res).into_future()) as Box, Error = hyper::error::Error> + Send + 'static> + Box::new(Ok(res).into_future()) + as Box< + hyper::rt::Future< + Item = hyper::Response, + Error = hyper::error::Error, + > + Send + + 'static, + > } else { let mut see_other = false; @@ -218,7 +232,12 @@ fn with_redirect( future, ) } - })) as Box, Error = hyper::error::Error> + Send + 'static> + })) + as Box< + hyper::rt::Future, Error = hyper::error::Error> + + Send + + 'static, + > } } @@ -228,14 +247,23 @@ fn request_with_redirect( uri: Uri, headers: Headers, body: Option, -) -> Result, Error = hyper::error::Error> + Send + 'static>> { - let request = request_builder(&method, &uri, &headers).body(if let Some(body) = body.clone() { - hyper::Body::from(body) - } else { - hyper::Body::empty() - })?; +) -> Result< + Box< + hyper::rt::Future, Error = hyper::error::Error> + + Send + + 'static, + >, +> { + let request = + request_builder(&method, &uri, &headers).body(if let Some(body) = body.clone() { + hyper::Body::from(body) + } else { + hyper::Body::empty() + })?; let future = client.request(request); - Ok(with_redirect(10, client, method, uri, headers, body, future)) + Ok(with_redirect( + 10, client, method, uri, headers, body, future, + )) } impl HyperClient { @@ -257,7 +285,12 @@ impl HyperClient { } #[cfg(feature = "openssl")] - pub fn connect_with_ssl(addr: &str, key: &Path, cert: &Path, ca: &Path) -> result::Result { + pub fn connect_with_ssl( + addr: &str, + key: &Path, + cert: &Path, + ca: &Path, + ) -> result::Result { let mut key_buf = Vec::new(); let mut cert_buf = Vec::new(); let mut ca_buf = Vec::new(); @@ -270,7 +303,8 @@ impl HyperClient { cert_file.read_to_end(&mut cert_buf)?; ca_file.read_to_end(&mut ca_buf)?; - let pkey = openssl::pkey::PKey::from_rsa(openssl::rsa::Rsa::private_key_from_pem(&key_buf)?)?; + let pkey = + openssl::pkey::PKey::from_rsa(openssl::rsa::Rsa::private_key_from_pem(&key_buf)?)?; let cert = openssl::x509::X509::from_pem(&cert_buf)?; let pkcs12 = openssl::pkcs12::Pkcs12::builder().build("", "", &pkey, &cert)?; let der = pkcs12.to_der()?; @@ -303,8 +337,15 @@ impl HttpClient for HyperClient { let res = self .tokio_runtime - .lock().unwrap() - .block_on(request_with_redirect(self.client.clone(), http::Method::GET, url, headers.clone(), None)?)?; + .lock() + .unwrap() + .block_on(request_with_redirect( + self.client.clone(), + http::Method::GET, + url, + headers.clone(), + None, + )?)?; Ok(Response::new(res)) } @@ -319,10 +360,15 @@ impl HttpClient for HyperClient { let res = self .tokio_runtime - .lock().unwrap() - .block_on( - request_with_redirect(self.client.clone(), http::Method::POST, url, headers.clone(), Some(body.to_string()))?, - )?; + .lock() + .unwrap() + .block_on(request_with_redirect( + self.client.clone(), + http::Method::POST, + url, + headers.clone(), + Some(body.to_string()), + )?)?; Ok(Response::new(res)) } @@ -332,8 +378,15 @@ impl HttpClient for HyperClient { let res = self .tokio_runtime - .lock().unwrap() - .block_on(request_with_redirect(self.client.clone(), http::Method::DELETE, url, headers.clone(), None)?)?; + .lock() + .unwrap() + .block_on(request_with_redirect( + self.client.clone(), + http::Method::DELETE, + url, + headers.clone(), + None, + )?)?; Ok(Response::new(res)) } @@ -352,8 +405,15 @@ impl HttpClient for HyperClient { let res = self .tokio_runtime - .lock().unwrap() - .block_on(request_with_redirect(self.client.clone(), http::Method::POST, url, headers.clone(), Some(buf))?)?; + .lock() + .unwrap() + .block_on(request_with_redirect( + self.client.clone(), + http::Method::POST, + url, + headers.clone(), + Some(buf), + )?)?; Ok(Response::new(res)) } @@ -372,8 +432,15 @@ impl HttpClient for HyperClient { let res = self .tokio_runtime - .lock().unwrap() - .block_on(request_with_redirect(self.client.clone(), http::Method::PUT, url, headers.clone(), Some(buf))?)?; + .lock() + .unwrap() + .block_on(request_with_redirect( + self.client.clone(), + http::Method::PUT, + url, + headers.clone(), + Some(buf), + )?)?; Ok(Response::new(res)) } diff --git a/src/lib.rs b/src/lib.rs index 2afc9b9..33baee6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,23 +35,23 @@ extern crate tokio; extern crate unix_socket; extern crate url; -mod response; -mod header; pub mod container; +pub mod credentials; mod docker; pub mod errors; pub mod filesystem; -mod hyper_client; +mod header; mod http_client; +mod hyper_client; pub mod image; mod options; pub mod process; +mod response; pub mod signal; pub mod stats; pub mod system; mod test; pub mod version; -pub mod credentials; pub use docker::Docker; pub use options::*; diff --git a/src/options.rs b/src/options.rs index 317f98a..a80eb4c 100644 --- a/src/options.rs +++ b/src/options.rs @@ -1,8 +1,8 @@ //! Options which can be passed to various `Docker` commands. +use std::collections::HashMap; use std::path::PathBuf; use std::time::Duration; -use std::collections::HashMap; use url::{self, form_urlencoded}; use serde::de::{DeserializeOwned, Deserializer}; diff --git a/src/response.rs b/src/response.rs index 18301ff..0d18717 100644 --- a/src/response.rs +++ b/src/response.rs @@ -1,8 +1,7 @@ +use std::error::Error as StdError; ///! Response from Dockerd ///! - use std::fmt; -use std::error::Error as StdError; use serde_json::value as json; @@ -150,9 +149,9 @@ mod progress_detail_opt { #[cfg(test)] mod tests { + use self::Response as R; use super::*; use serde_json; - use self::Response as R; #[test] #[cfg_attr(rustfmt, rustfmt_skip)] diff --git a/src/test.rs b/src/test.rs index 8f2bd41..b55a917 100644 --- a/src/test.rs +++ b/src/test.rs @@ -1,5 +1,6 @@ #![cfg(test)] +use super::ImageLayer; use container::{Container, ContainerInfo}; use filesystem::FilesystemChange; use hyper_client::Response; @@ -9,7 +10,6 @@ use serde_json; use stats::{Stats, StatsReader}; use system::SystemInfo; use version::Version; -use super::ImageLayer; #[test] fn get_containers() { @@ -147,7 +147,9 @@ fn get_stats_response() -> Response { let s2 = get_stats_single_event(2); let s3 = get_stats_single_event(3); Response::new( - response.body(hyper::Body::from(format!("{}\n{}\n{}", s1, s2, s3))).unwrap(), + response + .body(hyper::Body::from(format!("{}\n{}\n{}", s1, s2, s3))) + .unwrap(), ) }