Skip to main content

to_string_multiple_with_options

Function to_string_multiple_with_options 

Source
pub fn to_string_multiple_with_options<T: Serialize>(
    values: &[T],
    options: SerializerOptions,
) -> Result<String, Error>
Expand description

Serialize multiple documents into a YAML string with configurable Options.

Serializes each value in the provided slice as an individual YAML document. Documents are separated by a standard YAML document start marker (“—\n”). By default, no marker is emitted before the first document. When options.yaml_12 is enabled and options.no_lang_directive is false, each document emits its own %YAML 1.2 directive and document start marker, and later documents are preceded by an explicit document end marker (“…\n”) so the following directive is valid. With options.no_lang_directive enabled, only the separators between documents are emitted.

Example

use serde::Serialize;

#[derive(Serialize)]
struct Point { coords: Vec<i32> }

let docs = vec![Point { coords: vec![0,1] }, Point { coords: vec![3,2] }];
let options = serde_saphyr::ser_options! {
    indent_step: 2,
    compact_list_indent: true
};
let out = serde_saphyr::to_string_multiple_with_options(&docs, options).unwrap();
assert_eq!(out, "coords:\n- 0\n- 1\n---\ncoords:\n- 3\n- 2\n");