pub struct Document { /* private fields */ }Expand description
A format-neutral in-memory document: a parsed Value plus the
Format it was parsed from. Has no file or stdin coupling — construct
it from a string or any std::io::Read the caller supplies.
Implementations§
Source§impl Document
impl Document
Sourcepub fn parse(source: &str, format: Format) -> DocumentResult<Document>
pub fn parse(source: &str, format: Format) -> DocumentResult<Document>
Parse source in the given format.
Named parse (not from_str) deliberately: this takes an explicit
format argument, so it is not the single-argument std::str::FromStr
contract that from_str would imply.
Sourcepub fn from_reader<R: Read>(
reader: R,
format: Format,
) -> DocumentResult<Document>
pub fn from_reader<R: Read>( reader: R, format: Format, ) -> DocumentResult<Document>
Read reader fully to a String, then parse it in the given
format.
Reads only from the supplied reader — never touches the process’s
own stdin.
Sourcepub fn encode(&self) -> DocumentResult<String>
pub fn encode(&self) -> DocumentResult<String>
Re-render the current value in its format via Format::save.
This is a fresh, non-source-preserving render: comments and original
formatting are not retained. Use DocumentFile when the original
source’s formatting must survive an edit.