Skip to main content

Document

Struct Document 

Source
pub struct Document<'de> {
    pub ctx: Context<'de>,
    /* private fields */
}
Expand description

The result of parsing a TOML document.

Wraps the parsed Table tree and a Context that accumulates errors.

Access values via index operators (doc["key"]) which return MaybeItem, or use table_helper and to for typed conversion.

§Examples

let arena = toml_spanner::Arena::new();
let doc = toml_spanner::parse("name = 'world'", &arena).unwrap();
assert_eq!(doc["name"].as_str(), Some("world"));

Fields§

§ctx: Context<'de>
Available on crate feature from-toml only.

Implementations§

Source§

impl<'de> Document<'de>

Source

pub fn into_table(self) -> Table<'de>

Consumes the document and returns the underlying Table.

Source

pub fn into_item(self) -> Item<'de>

Converts the root table into an Item with the same span and payload.

Source

pub fn table(&self) -> &Table<'de>

Returns a shared reference to the root table.

Source

pub fn split(&mut self) -> (&mut Context<'de>, &Table<'de>)

Available on crate feature from-toml only.

Returns disjoint borrows of the Context and the root Table.

Useful when passing the context into TableHelper::new while still holding a reference to the table.

Source§

impl<'de> Document<'de>

Source

pub fn table_helper<'ctx>(&'ctx mut self) -> TableHelper<'ctx, 'ctx, 'de>

Available on crate feature from-toml only.

Creates a TableHelper for the root table.

Typical entry point for typed extraction. Extract fields with TableHelper::required and TableHelper::optional, then call TableHelper::require_empty to reject unknown keys.

Source

pub fn to<T: FromToml<'de>>(&mut self) -> Result<T, FromTomlError>

Available on crate feature from-toml only.

Converts the root table into a typed value T via FromToml.

§Errors

Returns FromTomlError containing all accumulated errors.

Source

pub fn to_allowing_errors<T>( &mut self, ) -> Result<(T, FromTomlError), FromTomlError>
where T: FromToml<'de>,

Available on crate feature from-toml only.

Converts the root table into a typed value T via FromToml. returning non-fatal errors alongside.

§Errors

Returns FromTomlError containing all accumulated errors.

Source

pub fn errors(&self) -> &[Error]

Available on crate feature from-toml only.

Returns the accumulated errors.

Source

pub fn has_errors(&self) -> bool

Available on crate feature from-toml only.

Returns true if any errors have been recorded.

Trait Implementations§

Source§

impl Debug for Document<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'de> Index<&str> for Document<'de>

Source§

type Output = MaybeItem<'de>

The returned type after indexing.
Source§

fn index(&self, key: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl Serialize for Document<'_>

Available on crate feature serde only.
Source§

fn serialize<S>(&self, ser: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<'de> Freeze for Document<'de>

§

impl<'de> !RefUnwindSafe for Document<'de>

§

impl<'de> !Send for Document<'de>

§

impl<'de> !Sync for Document<'de>

§

impl<'de> Unpin for Document<'de>

§

impl<'de> UnsafeUnpin for Document<'de>

§

impl<'de> !UnwindSafe for Document<'de>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.