Skip to main content

get_writer

Function get_writer 

Source
pub fn get_writer(format: &str) -> Result<OutputFormat, InvalidFormatError>
Expand description

Convenience factory that returns the OutputFormat variant for a given format string.

§Accepted values

Canonical formats are matched case-sensitively to mirror the Python and TypeScript SDKs. The HTTP-proxy aliases keep their case-insensitive, underscore/hyphen-tolerant matching as documented in apcore-toolkit/docs/features/output-writers.md.

InputVariantMatch style
"yaml"OutputFormat::Yamlexact
"registry"OutputFormat::Registryexact
"http_proxy" / "http-proxy" / "httpproxy"OutputFormat::HTTPProxycase-insensitive

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) */ }
}