From 33c6432dcb007b68008599a24d19fb724ebaf1ca Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Tue, 29 Jun 2021 19:57:22 +0200 Subject: [PATCH] Simplify example impl With this simplification, we save a bit of code on one side, but also showcase that errors from custom AsyncSource implementations are possible because the ConfigError type provides a variant for it. Signed-off-by: Matthias Beyer Tested-by: Matthias Beyer --- examples/async_source/main.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/examples/async_source/main.rs b/examples/async_source/main.rs index 979f8292..10befe05 100644 --- a/examples/async_source/main.rs +++ b/examples/async_source/main.rs @@ -54,16 +54,13 @@ struct HttpSource { format: FileFormat, } -impl HttpSource { - async fn call(&self) -> Result { - reqwest::get(&self.uri).await?.text().await - } -} - #[async_trait] impl AsyncSource for HttpSource { async fn collect(&self) -> Result, ConfigError> { - self.call() + reqwest::get(&self.uri) + .await + .map_err(|e| ConfigError::Foreign(Box::new(e)))? // error conversion is possible from custom AsyncSource impls + .text() .await .map_err(|e| ConfigError::Foreign(Box::new(e))) .and_then(|text| {