pub fn parse(url: &Url, provider: &dyn Provider) -> 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::provider::Provider;
use flowcore::errors::Result;
use std::env;
use url::Url;
use std::collections::BTreeMap;
// 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{};
// load the flow from `url = file:///example.toml` using the `dummy_provider`
flowrclib::compiler::parser::parse(&Url::parse("file:///example.toml").unwrap(), &dummy_provider)
.unwrap();