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
Integer(Cow<'a, str>)
An integer value. Contains a Cow<str>
representing the integer since integers can contain underscores.
Float(Cow<'a, str>)
A float value. Contains a Cow<str>
representing the float since floats can be formatted many different ways and
can contain underscores.
Boolean(bool)
A boolean value. Contains a bool
value since only true
and false
are allowed.
DateTime(DateTime<'a>)
A DateTime
value. Contains a DateTime
struct that has a date and optionally a time, fractional seconds, and
offset from UTC.
String(Cow<'a, str>, StrType)
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.
Array(Rc<Vec<Value<'a>>>)
An array value. Contains an Rc<Vec>
of Value
s contained in the Array
.
InlineTable(Rc<Vec<(Cow<'a, str>, Value<'a>)>>)
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]
fn int(int: i64) -> Value<'a>
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));
fn int_from_str<S>(int: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn float(float: f64) -> Value<'a>
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));
fn float_from_str<S>(float: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn bool(b: bool) -> Value<'a>
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));
fn bool_from_str<S>(b: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
fn date_from_int(
year: usize,
month: usize,
day: usize
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize
) -> Result<Value<'a>, TOMLError>
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());
fn date_from_str<S>(year: S, month: S, day: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn datetime_from_int(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize
) -> Result<Value<'a>, TOMLError>
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());
fn datetime_from_str<S>(
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
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());
fn datetime_frac_from_int(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
frac: usize
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
frac: usize
) -> Result<Value<'a>, TOMLError>
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());
fn datetime_frac_from_str<S>(
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
frac: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
frac: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
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());
fn datetime_offset_from_int(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
posneg: char,
off_hour: usize,
off_minute: usize
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
posneg: char,
off_hour: usize,
off_minute: usize
) -> Result<Value<'a>, TOMLError>
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());
fn datetime_offset_from_str<S>(
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
posneg: S,
off_hour: S,
off_minute: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
posneg: S,
off_hour: S,
off_minute: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
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());
fn datetime_zulu_from_int(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize
) -> Result<Value<'a>, TOMLError>
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 and
Err(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());
fn datetime_zulu_from_str<S>(
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
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());
fn datetime_full_zulu_from_int(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
frac: u64
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
frac: u64
) -> Result<Value<'a>, TOMLError>
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
"-". 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.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());
fn datetime_full_zulu_from_str<S>(
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
frac: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
frac: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
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());
fn datetime_full_from_int(
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
frac: u64,
posneg: char,
off_hour: usize,
off_minute: usize
) -> Result<Value<'a>, TOMLError>
year: usize,
month: usize,
day: usize,
hour: usize,
minute: usize,
second: usize,
frac: u64,
posneg: char,
off_hour: usize,
off_minute: usize
) -> Result<Value<'a>, TOMLError>
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());
fn datetime_full_from_str<S>(
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
frac: S,
posneg: S,
off_hour: S,
off_minute: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
year: S,
month: S,
day: S,
hour: S,
minute: S,
second: S,
frac: S,
posneg: S,
off_hour: S,
off_minute: S
) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
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());
fn datetime_parse<S>(dt: S) -> Result<Value<'a>, TOMLError> where
S: Into<&'a str>,
S: Into<&'a str>,
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());
fn basic_string<S>(s: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn ml_basic_string<S>(s: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn literal_string<S>(s: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn ml_literal_string<S>(s: S) -> Result<Value<'a>, TOMLError> where
S: Into<String> + Clone,
S: Into<String> + Clone,
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());
fn validate(&self) -> bool
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]
impl<'a> PartialEq for Value<'a>
[src]
fn eq(&self, __arg_0: &Value<'a>) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, __arg_0: &Value<'a>) -> bool
This method tests for !=
.
impl<'a> Eq for Value<'a>
[src]
impl<'a> Clone for Value<'a>
[src]
fn clone(&self) -> Value<'a>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
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 Integer
s, f64
for Float
s, bool
for Boolean
s. The default formatting for Array
s and InlineTable
s 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
.