pub trait ScriptHost: Send + Sync {
// Required methods
fn http_get(
&self,
url: &str,
headers: BTreeMap<String, String>,
) -> Result<String, String>;
fn http_post(
&self,
url: &str,
body: &str,
headers: BTreeMap<String, String>,
) -> Result<String, String>;
fn shell(&self, command: &str) -> Result<String, String>;
fn read_file(&self, path: &str) -> Result<String, String>;
fn write_file(&self, path: &str, content: &str) -> Result<String, String>;
fn env_var(&self, name: &str) -> Result<String, String>;
}Expand description
The side-effecting host functions a script tool can call. Implemented by the
daemon (with permission enforcement + real I/O) and by tests (with canned
responses). Every method returns Result<String, String>; an Err(msg) is
turned into a Rhai exception by the tool engine, which surfaces to the
agent as an [error] … result.
Required Methods§
Sourcefn http_get(
&self,
url: &str,
headers: BTreeMap<String, String>,
) -> Result<String, String>
fn http_get( &self, url: &str, headers: BTreeMap<String, String>, ) -> Result<String, String>
HTTP GET url with the given request headers, returning the response body.
Sourcefn http_post(
&self,
url: &str,
body: &str,
headers: BTreeMap<String, String>,
) -> Result<String, String>
fn http_post( &self, url: &str, body: &str, headers: BTreeMap<String, String>, ) -> Result<String, String>
HTTP POST body to url with the given headers, returning the response body.
Sourcefn shell(&self, command: &str) -> Result<String, String>
fn shell(&self, command: &str) -> Result<String, String>
Run a shell command, returning its combined output.
Sourcefn read_file(&self, path: &str) -> Result<String, String>
fn read_file(&self, path: &str) -> Result<String, String>
Read a file (confined to the agent workdir by the implementor).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".