pub fn get_writer(format: &str) -> Result<OutputFormat, OutputFormatError>Expand description
Convenience factory that returns the OutputFormat variant for a given
format string.
§Accepted values (case-insensitive)
| Input | Variant |
|---|---|
"yaml" | OutputFormat::Yaml |
"registry" | OutputFormat::Registry |
"http_proxy" / "http-proxy" / "httpproxy" | OutputFormat::HttpProxy |
Returns Err for unrecognised strings.
§Usage
use apcore_toolkit::output::get_writer;
use apcore_toolkit::output::OutputFormat;
let fmt = get_writer("yaml").unwrap();
assert_eq!(fmt, OutputFormat::Yaml);
// Then instantiate the concrete writer:
match fmt {
OutputFormat::Yaml => { /* use YAMLWriter */ }
OutputFormat::Registry => { /* use RegistryWriter */ }
// OutputFormat::HttpProxy (feature "http-proxy") => use HTTPProxyRegistryWriter
#[allow(unreachable_patterns)]
_ => { /* other variants (e.g. HttpProxy when the `http-proxy` feature is enabled) */ }
}