Skip to main content

from_str_multiple_with_options

Function from_str_multiple_with_options 

Source
pub fn from_str_multiple_with_options<'de, T, C>(
    input: &'de str,
    options: Options,
) -> Result<C, Error>
where T: Deserialize<'de>, C: Default + Extend<T>,
Expand description

Deserialize multiple YAML documents into a collection with configurable Options, supporting borrowed values. Null documents are skipped as described in from_multiple_with_options. Application-tagged roots are deserialized, even with null payloads.

Like from_str_multiple, this function supports both owned values and values borrowing from the input string, collected into any C: Default + Extend<T>. Borrowed values cannot outlive the input, and strings requiring transformation cannot be borrowed as &str. Use from_multiple_with_options to return a Vec<T> with a single type argument.

use std::collections::BTreeSet;

let yaml = String::from("first\n---\nsecond\n---\nfirst\n");
let options = serde_saphyr::options! { with_snippet: false };
let values = serde_saphyr::from_str_multiple_with_options::<&str, BTreeSet<_>>(&yaml, options)?;
assert_eq!(values, BTreeSet::from(["first", "second"]));