From 7c0be818e1dbe204a2f5de746987e4c19e436a7c Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Mon, 9 Aug 2021 01:29:01 +0100 Subject: [PATCH] server: use meta.need Signed-off-by: Ian Jackson --- src/bin/server.rs | 7 +------ src/multipart.rs | 4 ++-- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/bin/server.rs b/src/bin/server.rs index c5eaf92..42e3785 100644 --- a/src/bin/server.rs +++ b/src/bin/server.rs @@ -90,12 +90,7 @@ async fn handle( let mut meta = MetadataFieldIterator::new(comp.payload_start); - let client = meta.next() - .map(|r| r.map_err(Into::into)) - .unwrap_or_else(|| Err(anyhow!("missing"))) - .context("client addr")?; - - let client: IpAddr = client.parse().context("client address")?; + let client: ClientName = meta.need().context("client addr")?; // let client = all_clients.get(&client).ok_or_else(|| anyhow!(BAD_CLIENT))?; eprintln!("boundary={:?} start={} name={:?} client={}", diff --git a/src/multipart.rs b/src/multipart.rs index 5099f05..0eaabda 100644 --- a/src/multipart.rs +++ b/src/multipart.rs @@ -90,7 +90,7 @@ impl<'b> MetadataFieldIterator<'b> { #[throws(AE)] pub fn need(&mut self) -> T where T: FromStr, - T::Err: std::error::Error + Sync + Send + 'static, + AE: From, { self.parse()?.ok_or_else(|| anyhow!("missing"))? } @@ -98,7 +98,7 @@ impl<'b> MetadataFieldIterator<'b> { #[throws(AE)] pub fn parse(&mut self) -> Option where T: FromStr, - T::Err: std::error::Error + Sync + Send + 'static, + AE: From, { let s = if let Some(r) = self.next() { r? } else { return None }; Some(s.parse()?) -- 2.30.2