Enum tomllib::types::Value [] [src]

pub enum Value<'a> {
    Integer(Cow<'a, str>),
    Float(Cow<'a, str>),
    Boolean(bool),
    DateTime(DateTime<'a>),
    String(Cow<'a, str>, StrType),
    Array(Rc<Vec<Value<'a>>>),
    InlineTable(Rc<Vec<(Cow<'a, str>, Value<'a>)>>),
}

Variants

An integer value. Contains a Cow<str> representing the integer since integers can contain underscores.

A float value. Contains a Cow<str> representing the float since floats can be formatted many different ways and can contain underscores.

A boolean value. Contains a bool value since only true and false are allowed.

A DateTime value. Contains a DateTime struct that has a date and optionally a time, fractional seconds, and offset from UTC.

A string value. Contains a Cow<str> with the string contents (without quotes) and StrType indicating whether the string is a basic string, multi-line basic string, literal string or multi-line literal string.

An array value. Contains an Rc<Vec> of Values contained in the Array.

An inline table value. Contains an Rc<Vec> of tuples that contain a Cow<str> representing a key, and Value that the key points to.

Methods

impl<'a> Value<'a>
[src]

Convenience function for creating an Value::Integer from an i64. Cannot fail since i64 maps directly onto TOML integers.

Examples

use tomllib::types::Value;

assert_eq!(Value::Integer("100".into()), Value::int(100));

Convenience function for creating an Value::Integer from an string type. Returns Ok(Integer) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::Value;

assert_eq!(Value::Integer("200".into()), Value::int_from_str("200").unwrap());

Convenience function for creating a Value::Float from a f64. Cannot fail since f64 maps directly onto TOML floats.

Examples

use tomllib::types::Value;

assert_eq!(Value::Float("300.3".into()), Value::float(300.3));

Convenience function for creating a Value::Float from an string type. Returns Ok(Float) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::Value;

assert_eq!(Value::Float("400.4".into()), Value::float_from_str("400.4").unwrap());

Convenience function for creating a Value::Boolean from a bool. Cannot fail since bool maps directly onto TOML booleans.

Examples

use tomllib::types::Value;

assert_eq!(Value::Boolean(true), Value::bool(true));

Convenience function for creating a Value::DateTime containing only a date from integer values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(), None)),
  Value::date_from_int(2010, 4, 10).unwrap());

Convenience function for creating a Value::DateTime containing only a date from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(), None)),
  Value::date_from_str("2011", "05", "11").unwrap());

Convenience function for creating a Value::DateTime containing a date and time from integer values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(),
  Some(Time::from_str("01", "02", "03", None, None).unwrap()))),
  Value::datetime_from_int(2010, 4, 10, 1, 2, 3).unwrap());

Convenience function for creating a Value::DateTime containing a date and time from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(),
  Some(Time::from_str("02", "03", "04", None, None).unwrap()))),
  Value::datetime_from_str("2011", "05", "11", "02", "03", "04").unwrap());

Convenience function for creating a Value::DateTime containing a date and time with fractional seconds from integer values. Returns Ok(DateTime) on success and Err(TOMLError) on failure. Note, you can't represent leading zeros on the fractional part this way for example: 2016-03-15T08:05:22.00055 is not possible using this function.

Examples

use tomllib::types::{Value, DateTime, Date, Time};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(),
  Some(Time::from_str("01", "02", "03", Some("5432".into()), None).unwrap()))),
  Value::datetime_frac_from_int(2010, 4, 10, 1, 2, 3, 5432).unwrap());

Convenience function for creating a Value::DateTime containing a date and time with fractional seconds from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(),
  Some(Time::from_str("02", "03", "04", Some("0043".into()), None).unwrap()))),
  Value::datetime_frac_from_str("2011", "05", "11", "02", "03", "04", "0043").unwrap());

Convenience function for creating a Value::DateTime containing a date and time with a timezone offset from UTC from integer values, except for the plus/minus sign which is passed as a char '+' or '-'. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset, TimeOffsetAmount};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(),
  Some(Time::from_str("01", "02", "03", None, Some(TimeOffset::Time(TimeOffsetAmount::from_str(
    "+", "08", "00"
  ).unwrap()))).unwrap()))),
  Value::datetime_offset_from_int(2010, 4, 10, 1, 2, 3, '+', 8, 0).unwrap());

Convenience function for creating a Value::DateTime containing a date and time with a timezone offset from UTC from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset, TimeOffsetAmount};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(),
  Some(Time::from_str("02", "03", "04", None, Some(TimeOffset::Time(TimeOffsetAmount::from_str(
    "+", "09", "30"
  ).unwrap()))).unwrap()))),
  Value::datetime_offset_from_str("2011", "05", "11", "02", "03", "04", "+", "09", "30").unwrap());

Convenience function for creating a Value::DateTime containing a date and time with a timezone of Zulu from integer values. Returns Ok(DateTime)on success andErr(TOMLError)` on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(),
  Some(Time::from_str("01", "02", "03", None, Some(TimeOffset::Zulu)).unwrap()))),
  Value::datetime_zulu_from_int(2010, 4, 10, 1, 2, 3).unwrap());

Convenience function for creating a Value::DateTime containing a date and time with a timezone of Zulu from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(),
  Some(Time::from_str("02", "03", "04", None, Some(TimeOffset::Zulu)).unwrap()))),
  Value::datetime_zulu_from_str("2011", "05", "11", "02", "03", "04").unwrap());

Convenience function for creating a Value::DateTime containing a date and time with fractional seconds and a timezone of Zulu from integer values, except for the plus/minus sign which is passed as a string value "+" or "-". ReturnsOk(DateTime)on success andErr(TOMLError)on failure. Note, you can't represent leading zeros on the fractional part this way for example:2016-03-15T08:05:22.00055Z` is not possible using this function.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(),
  Some(Time::from_str("01", "02", "03", Some("5678".into()), Some(TimeOffset::Zulu)).unwrap()))),
  Value::datetime_full_zulu_from_int(2010, 4, 10, 1, 2, 3, 5678).unwrap());

Convenience function for creating a Value::DateTime containing a date and time with fractional seconds and a timezone of Zulu from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(),
  Some(Time::from_str("02", "03", "04", None, Some(TimeOffset::Zulu)).unwrap()))),
  Value::datetime_zulu_from_str("2011", "05", "11", "02", "03", "04").unwrap());

Convenience function for creating a Value::DateTime containing a date and time with fractional seconds and a timezone offset from UTC from integer values, except for the plus/minus sign which is passed as a char "+" or "-". Returns Ok(DateTime) on success and Err(TOMLError) on failure. Note, you can't represent leading zeros on the fractional part this way for example: 2016-03-15T08:05:22.00055-11:00 is not possible using this function.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset, TimeOffsetAmount};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2010", "04", "10").unwrap(),
  Some(Time::from_str("01", "02", "03", Some("135".into()), Some(TimeOffset::Time(TimeOffsetAmount::from_str(
    "-", "11", "00"
  ).unwrap()))).unwrap()))),
  Value::datetime_full_from_int(2010, 4, 10, 1, 2, 3, 135, '-', 11, 0).unwrap());

Convenience function for creating a Value::DateTime containing a date and time with fractional seconds and a timezone offset from UTC from string values. Returns Ok(DateTime) on success and Err(TOMLError) on failure.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset, TimeOffsetAmount};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2011", "05", "11").unwrap(),
  Some(Time::from_str("02", "03", "04", Some("0864".into()), Some(TimeOffset::Time(TimeOffsetAmount::from_str(
    "+", "09", "30"
  ).unwrap()))).unwrap()))),
  Value::datetime_full_from_str("2011", "05", "11", "02", "03", "04", "0864","+", "09", "30").unwrap());

Convenience function for creating a Value::DateTime from a sinle string value.

Examples

use tomllib::types::{Value, DateTime, Date, Time, TimeOffset, TimeOffsetAmount};

assert_eq!(Value::DateTime(DateTime::new(Date::from_str("2012", "06", "12").unwrap(),
  Some(Time::from_str("02", "03", "04", Some("0864".into()), Some(TimeOffset::Time(TimeOffsetAmount::from_str(
    "+", "10", "30"
  ).unwrap()))).unwrap()))),
  Value::datetime_parse("2012-06-12T02:03:04.0864+10:30").unwrap());

Convenience function for creating a Value::String with StrType::Basic. Returns Ok() on success and Err() on failure.

Examples

use tomllib::types::{Value, StrType};

assert_eq!(Value::String("foobar".into(), StrType::Basic), Value::basic_string("foobar").unwrap());

Convenience function for creating a Value::String with StrType::MLBasic. Returns Ok() on success and Err() on failure.

Examples

use tomllib::types::{Value, StrType};

assert_eq!(Value::String("foo\nbar".into(), StrType::MLBasic), Value::ml_basic_string("foo\nbar").unwrap());

Convenience function for creating a Value::String with StrType::Literal. Returns Ok() on success and Err() on failure.

Examples

use tomllib::types::{Value, StrType};

assert_eq!(Value::String("\"foobar\"".into(), StrType::Literal), Value::literal_string("\"foobar\"").unwrap());

Convenience function for creating a Value::String with StrType::MLLiteral. Returns Ok() on success and Err() on failure.

Examples

use tomllib::types::{Value, StrType};

assert_eq!(Value::String("\"foo\nbar\"".into(), StrType::MLLiteral),
  Value::ml_literal_string("\"foo\nbar\"").unwrap());

Parses and validates a Value, returns true if the value is valid and false if it is invalid.

Examples

use tomllib::types::{Value};

assert!(!Value::Integer("_989_721_".into()).validate()); // Integers may have underscores but they must be
                                                          // surrounded by digits
assert!(Value::Float("7.62".into()).validate());

Trait Implementations

impl<'a> Debug for Value<'a>
[src]

Formats the value using the given formatter.

impl<'a> PartialEq for Value<'a>
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<'a> Eq for Value<'a>
[src]

impl<'a> Clone for Value<'a>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<'a> Display for Value<'a>
[src]

Formats a Value for display. Uses default rust formatting for for i64 for Integers, f64 for Floats, bool for Booleans. The default formatting for Arrays and InlineTables is No whitespace after/before opening/closing braces, no whitespace before and one space after all commas, no comments on the same line as the Array or InlineTable, and one space before and after an equals sign in an InlineTable.

Formats the value using the given formatter. Read more