Skip to main content

from_bytes_multiple_with_options

Function from_bytes_multiple_with_options 

Source
pub fn from_bytes_multiple_with_options<'de, T, C>(
    bytes: &'de [u8],
    options: Options,
) -> Result<C, Error>
where T: Deserialize<'de>, C: Default + Extend<T>,
Expand description

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

Like from_bytes_multiple, this function supports owned values and values borrowing from the input byte slice, collected into any C: Default + Extend<T>. Borrowed values cannot outlive the input, and strings requiring transformation cannot be borrowed as &str. Invalid UTF-8 returns Error::InvalidUtf8Input. Use from_slice_multiple_with_options to return a Vec<T> with a single type argument.

use std::collections::VecDeque;

let bytes = b"first\n---\nsecond\n".to_vec();
let options = serde_saphyr::options! { with_snippet: false };
let values = serde_saphyr::from_bytes_multiple_with_options::<&str, VecDeque<_>>(&bytes, options)?;
assert_eq!(values, VecDeque::from(["first", "second"]));