Skip to main content

from_str_borrowed

Function from_str_borrowed 

Source
pub fn from_str_borrowed(input: &str) -> Result<BorrowedValue<'_>>
Expand description

Parse YAML into a zero-copy BorrowedValue that borrows from the input.

This is significantly faster than from_str::<Value> for large documents because string scalars and mapping keys borrow directly from the input buffer instead of allocating on the heap.

ยงExamples

use noyalib::borrowed::{from_str_borrowed, BorrowedValue};

let yaml = "host: localhost\nport: 8080\n";
let value = from_str_borrowed(yaml).unwrap();
assert_eq!(value.as_mapping().unwrap().get("host").unwrap().as_str(), Some("localhost"));