Skip to main content

SourceDocument

Enum SourceDocument 

Source
pub enum SourceDocument {
    Empty,
    Content {
        root: Table,
        trailing: String,
    },
}
Expand description

One of the two documents a merge is given, after parsing.

Zero bytes and “parsed, but declares no keys” are different states, and only byte length decides which. A file holding # notes to self is not empty: it has text that has to survive the merge, and default keys are written in beneath it. Only a file of no length has nothing to preserve.

Variants§

§

Empty

Zero bytes. Nothing to parse, nothing to keep.

§

Content

Text that parsed. The root table may hold no keys, which is a document with content all the same.

Fields

§root: Table

The root table. Every key, table and array of tables in the document nests inside it.

§trailing: String

Whitespace and comments after the last element, which belong to no key. A comment-only document is all trailing and no keys.

Implementations§

Source§

impl SourceDocument

Source

pub fn parse(src: &str) -> Result<Self, TomlError>

Parses a document, keeping nothing but the root table and the trailing text. Spans are discarded; use SourceDocument::parse_with_spans for the document diagnostics point into.

Source

pub fn parse_with_spans(src: &str) -> Result<(Self, SpanIndex), TomlError>

Parses a document and harvests its key spans first.

Document::into_mut resolves spans into owned strings and the span() accessors then return None, so positions have to be taken before the conversion. There is no way back.

Source

pub fn root(&self) -> Option<&Table>

The root table, or None for a zero-byte document.

Source

pub fn trailing(&self) -> &str

The text after the last element, empty for a zero-byte document.

Source

pub fn has_text_but_no_keys(&self) -> bool

Whether the document parsed and declares no keys. A zero-byte document is not one of these: it has no text at all.

Trait Implementations§

Source§

impl Clone for SourceDocument

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SourceDocument

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.