1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use super::{Ctx, Handler};

use crate::capability::config::{self, runtime};

use async_trait::async_trait;
use tracing::instrument;

/// `wasi:config/runtime` implementation
#[async_trait]
pub trait Config {
    /// Handle `wasi:config/runtime.get`
    async fn get(
        &self,
        key: &str,
    ) -> anyhow::Result<Result<Option<String>, config::runtime::ConfigError>>;

    /// Handle `wasi:config/runtime.get_all`
    async fn get_all(
        &self,
    ) -> anyhow::Result<Result<Vec<(String, String)>, config::runtime::ConfigError>>;
}

#[async_trait]
impl<H: Handler> runtime::Host for Ctx<H> {
    #[instrument(skip(self))]
    async fn get(
        &mut self,
        key: String,
    ) -> anyhow::Result<Result<Option<String>, config::runtime::ConfigError>> {
        Config::get(&self.handler, &key).await
    }

    #[instrument(skip_all)]
    async fn get_all(
        &mut self,
    ) -> anyhow::Result<Result<Vec<(String, String)>, config::runtime::ConfigError>> {
        self.handler.get_all().await
    }
}