pub fn load(
    url: &Url,
    provider: &dyn Provider,
    source_urls: &mut HashSet<(Url, Url)>
) -> Result<Process>
Expand description

Load a Flow definition from a Url, recursively loading all sub-processes referenced.

The return is a Result containing the Process, or a String describing the error found while loading.

Example

use flowcore::meta_provider::Provider;
use flowcore::errors::Result;
use std::env;
use url::Url;
use std::collections::HashSet;

// Clients need to provide a Provider of content for the loader as flowlibc is independent of
// file systems and io.
struct DummyProvider;

// A Provider must implement the `Provider` trait, with the methods to `resolve` a URL and to
// `get` the contents for parsing.
impl Provider for DummyProvider {
    fn resolve_url(&self, url: &Url, default_filename: &str, _ext: &[&str]) -> Result<(Url, Option<Url>)> {
       // Just fake the url resolution in this example
       Ok((url.clone(), None))
    }

   fn get_contents(&self, url: &Url) -> Result<Vec<u8>> {
       // Return the simplest flow definition possible - ignoring the url passed in
       Ok("flow = \"test\"".as_bytes().to_owned())
    }
}

// Create an instance of the `DummyProvider`
let dummy_provider = DummyProvider{};

// keep track of the source Urls loaded for this flow
let mut source_urls = HashSet::<(Url, Url)>::new();

// load the flow from `url = file:///example.toml` using the `dummy_provider`
flowclib::compiler::loader::load(&Url::parse("file:///example.toml").unwrap(), &dummy_provider, &mut source_urls).unwrap();