Skip to main content

format_with_parser_config

Function format_with_parser_config 

Source
pub fn format_with_parser_config(
    input: &str,
    config: &FormatConfig,
    parser: &ParserConfig,
) -> Result<String>
Expand description

Auto-formats a YAML stream under the given formatter and parser configuration.

The input is parsed as by crate::cst::parse_stream_with_config: max_stream_bytes, max_documents, max_document_length and the other limits of parser apply, so a formatter that runs on untrusted input can bound the work it does.

§Errors

Returns the parse or budget error the input trips under parser, or an error when the input cannot be re-laid out without changing its meaning (see format()).

§Examples

use noyalib::cst::{FormatConfig, format_with_parser_config};
use noyalib::ParserConfig;

let strict = ParserConfig::strict();
let out = format_with_parser_config("a:   1\n", &FormatConfig::default(), &strict).unwrap();
assert_eq!(out, "a: 1\n");

let one_doc = ParserConfig::new().max_documents(1);
let stream = "--- 1\n--- 2\n";
assert!(format_with_parser_config(stream, &FormatConfig::default(), &one_doc).is_err());