diff options
author | Matthias Beyer <mail@beyermatthias.de> | 2021-06-29 19:57:22 +0200 |
---|---|---|
committer | Radosław Kot <rdkt13@gmail.com> | 2021-07-03 20:30:21 +0200 |
commit | 33c6432dcb007b68008599a24d19fb724ebaf1ca (patch) | |
tree | b1b0d00debe1545f25097ac2d3c0ba4cf01a6b50 | |
parent | 18f01fd6f628f74ec6a340c8f554995148616f2f (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.rs | 11 |
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| { |