Struct toml_span::value::Value

source ·
pub struct Value<'de> {
    pub span: Span,
    /* private fields */
}
Expand description

A deserialized ValueInner with accompanying Span information for where it was located in the toml document

Fields§

§span: Span

The location of the value in the toml document

Implementations§

source§

impl<'de> Value<'de>

source

pub fn new(value: ValueInner<'de>) -> Self

Creates a new Value with an empty Span

source

pub fn with_span(value: ValueInner<'de>, span: Span) -> Self

Creates a new Value with the specified Span

source

pub fn take(&mut self) -> ValueInner<'de>

Takes the inner ValueInner

This panics if the inner value has already been taken.

Typically paired with Self::set

source

pub fn set(&mut self, value: ValueInner<'de>)

Sets the inner ValueInner

This is typically done when the value is taken with Self::take, processed, and returned

source

pub fn has_keys(&self) -> bool

Returns true if the value is a table and is non-empty

source

pub fn has_key(&self, key: &str) -> bool

Returns true if the value is a table and has the specified key

source

pub fn take_string( &mut self, msg: Option<&'static str> ) -> Result<Cow<'de, str>, Error>

Takes the value as a string, returning an error with either a default or user supplied message

source

pub fn as_str(&self) -> Option<&str>

Returns a borrowed string if this is a ValueInner::String

source

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

Returns a borrowed table if this is a ValueInner::Table

source

pub fn as_array(&self) -> Option<&Array<'de>>

Returns a borrowed array if this is a ValueInner::Array

source

pub fn as_integer(&self) -> Option<i64>

Returns an i64 if this is a ValueInner::Integer

source

pub fn as_float(&self) -> Option<f64>

Returns an f64 if this is a ValueInner::Float

source

pub fn as_bool(&self) -> Option<bool>

Returns a bool if this is a ValueInner::Boolean

source

pub fn pointer(&self, pointer: &'de str) -> Option<&Self>

Uses JSON pointer-like syntax to lookup a specific Value

The basic format is:

  • The path starts with /
  • Each segment is separated by a /
  • Each segment is either a key name, or an integer array index
let data = "[x]\ny = ['z', 'zz']";
let value = toml_span::parse(data).unwrap();
assert_eq!(value.pointer("/x/y/1").unwrap().as_str().unwrap(), "zz");
assert!(value.pointer("/a/b/c").is_none());

Note that this is JSON pointer**-like** because / is not supported in key names because I don’t see the point. If you want this it is easy to implement.

source

pub fn pointer_mut(&mut self, pointer: &'de str) -> Option<&mut Self>

The mut version of Self::pointer

Trait Implementations§

source§

impl<'de> AsRef<ValueInner<'de>> for Value<'de>

source§

fn as_ref(&self) -> &ValueInner<'de>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<'de> Debug for Value<'de>

source§

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

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

impl<'de> Serialize for Value<'de>

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> RefUnwindSafe for Value<'de>

§

impl<'de> Send for Value<'de>

§

impl<'de> Sync for Value<'de>

§

impl<'de> Unpin for Value<'de>

§

impl<'de> UnwindSafe for Value<'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>,

§

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>,

§

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.