Skip to content

Commit 33c6432

Browse files
matthiasbeyerszarykott
authored andcommitted
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 <[email protected]> Tested-by: Matthias Beyer <[email protected]>
1 parent 18f01fd commit 33c6432

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

examples/async_source/main.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,13 @@ struct HttpSource {
5454
format: FileFormat,
5555
}
5656

57-
impl HttpSource {
58-
async fn call(&self) -> Result<String, reqwest::Error> {
59-
reqwest::get(&self.uri).await?.text().await
60-
}
61-
}
62-
6357
#[async_trait]
6458
impl AsyncSource for HttpSource {
6559
async fn collect(&self) -> Result<HashMap<String, config::Value>, ConfigError> {
66-
self.call()
60+
reqwest::get(&self.uri)
61+
.await
62+
.map_err(|e| ConfigError::Foreign(Box::new(e)))? // error conversion is possible from custom AsyncSource impls
63+
.text()
6764
.await
6865
.map_err(|e| ConfigError::Foreign(Box::new(e)))
6966
.and_then(|text| {

0 commit comments

Comments
 (0)