Interactive development in Rust: Environments

Previously I talked about 'tools', which provide a simple API to any single purpose program.

What I'm working on is a more interactive way to build software. Tools take input and provide output in the form of JSON, so it's reasonably easy for a person to write and read what's going on. However, one more thing is required: we need to be able to name a tool and retrieve it from the program.

What I'm using is going to be called an 'Environment', and it's a trait that looks like this:

pub trait Environment : Send {
    fn get_json_tool(&self, name: &str) -> Result<Box<Tool>, RetrieveToolError>;

This is all we need to be able to retrieve tools: it should be pretty easy to imagine building a tool that makes it possible to execute simple commands like sort [ 3,6,5,2 ] and produce a result. The output is just JSON so it's pretty easy to see how to chain these things together too.

With just these two components, it becomes possible to interact with anything that implements the interface and is exposed via a suitable Environment object. It's already possible to build something interesting this way: add in a web server and we have an instant microservice - but the web server isn't mandatory: debugging and operating this from the command line is entirely possible.