From 3914b2189069783e6d538f2d742525284c8951c2 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Sat, 4 Jul 2020 02:55:33 +0200 Subject: server: Rename `Error::WriteError` to `Error::Write` and remove context Since we don't actually need any additional context here, we can remove it. Since that allows us to avoid calling `context()` with the `WriteError` context selector, we can then safely rename `WriteError` to `Write`. --- src/server.rs | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) (limited to 'src/server.rs') diff --git a/src/server.rs b/src/server.rs index e3e5d9a..2b70c0d 100644 --- a/src/server.rs +++ b/src/server.rs @@ -13,8 +13,8 @@ const HTTP_VERSION: &'static str = "HTTP/1.1"; #[derive(Debug, Snafu)] pub enum Error { - #[snafu(display("{}", source))] - WriteError { source: io::Error }, + #[snafu(context(false))] + Write { source: io::Error }, #[snafu(display("Couldn't build request: {}", source))] RequestBuilder { source: request::Error }, @@ -35,7 +35,7 @@ impl Server { // TODO: log // Ignore write errors as clients will have closed the // connection by this point. - Err(Error::WriteError { .. }) => (), + Err(Error::Write { .. }) => (), Err(Error::RequestBuilder { .. }) => internal_server_error(&mut raw_request.stdout()), @@ -70,21 +70,20 @@ where H: Handler + 'static + Sync HTTP_VERSION, head.status.as_str(), head.status.canonical_reason().unwrap_or("UNKNOWN"), - ) - .context(WriteError)?; + )?; for (name, value) in head.headers.iter() { - write!(&mut stdout, "{}: ", name).context(WriteError)?; - stdout.write(value.as_bytes()).context(WriteError)?; - stdout.write(b"\r\n").context(WriteError)?; + write!(&mut stdout, "{}: ", name)?; + stdout.write(value.as_bytes())?; + stdout.write(b"\r\n")?; } - stdout.write(b"\r\n").context(WriteError)?; + stdout.write(b"\r\n")?; match body { - conduit::Body::Static(slice) => stdout.write(slice).map(|_| ()).context(WriteError)?, - conduit::Body::Owned(vec) => stdout.write(&vec).map(|_| ()).context(WriteError)?, - conduit::Body::File(mut file) => io::copy(&mut file, &mut stdout).map(|_| ()).context(WriteError)?, + conduit::Body::Static(slice) => stdout.write(slice).map(|_| ())?, + conduit::Body::Owned(vec) => stdout.write(&vec).map(|_| ())?, + conduit::Body::File(mut file) => io::copy(&mut file, &mut stdout).map(|_| ())?, }; Ok(()) -- cgit v1.2.3