summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2021-06-29 19:57:22 +0200
committerRadosław Kot <rdkt13@gmail.com>2021-07-03 20:30:21 +0200
commit33c6432dcb007b68008599a24d19fb724ebaf1ca (patch)
treeb1b0d00debe1545f25097ac2d3c0ba4cf01a6b50
parent18f01fd6f628f74ec6a340c8f554995148616f2f (diff)
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 <mail@beyermatthias.de> Tested-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--examples/async_source/main.rs11
1 files changed, 4 insertions, 7 deletions
diff --git a/examples/async_source/main.rs b/examples/async_source/main.rs
index 979f829..10befe0 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<String, reqwest::Error> {
- reqwest::get(&self.uri).await?.text().await
- }
-}
-
#[async_trait]
impl AsyncSource for HttpSource {
async fn collect(&self) -> Result<HashMap<String, config::Value>, 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| {