Skip to main content

parse

Function parse 

Source
pub fn parse(input: &str) -> Result<Source, ParseError>
Expand description

Parse a SOURCE[(OPTIONS)][:RESOURCE] configuration source string.

Equivalent to Source::parse. See the crate-level documentation for the format and rules.

ยงExamples

use tanzim_source::parse;

let source = parse("env(prefix=APP_)")?;
assert_eq!(source.source(), "env");
assert_eq!(source.resource(), "");

let file = parse("file:app.toml")?;
assert_eq!(file.source(), "file");
assert_eq!(file.resource(), "app.toml");

A malformed source string returns a ParseError. Use {error:#} to render the input snippet with a caret pointing at the offending column:

use tanzim_source::parse;

let error = parse("file(bad").unwrap_err();
println!("{error:#}");

which prints:

invalid configuration source at column 9: configuration source: expected option value after `=`, found end of input
  file(bad
         ^