Skip to content

Commit

Permalink
Simplify example impl
Browse files Browse the repository at this point in the history
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 <[email protected]>
Tested-by: Matthias Beyer <[email protected]>
  • Loading branch information
matthiasbeyer authored and szarykott committed Jul 3, 2021
1 parent 18f01fd commit 33c6432
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions examples/async_source/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down

0 comments on commit 33c6432

Please sign in to comment.