Enum keyvalues_parser::Value[][src]

pub enum Value<'a> {
    Str(Cow<'a, str>),
    Obj(Obj<'a>),
}
Expand description

Enum representing all valid VDF values

VDF is composed of Keys and their respective Values where this represents the latter. A value is either going to be a Str(Cow<str>), or an Obj(Obj) that contains a list of keys and values.

Variants

Str

Tuple Fields of Str

0: Cow<'a, str>
Obj

Tuple Fields of Obj

0: Obj<'a>

Implementations

Returns if the current value is the Str variant

Returns if the current value is the Obj variant

Gets the inner &str if this is a Value::Str

Gets the inner &Obj if this value is a Value::Obj

Gets the inner &mut str if this is a Value::Str

Gets the inner &mut Obj if this is a Value::Obj

Unwraps the Cow<str> from the Value::Str

Panics

If the variant was Value::Obj

Examples

use keyvalues_parser::Value;
use std::borrow::Cow;

let value = Value::Str(Cow::from("Sample text"));
assert_eq!(value.unwrap_str(), "Sample text");
use keyvalues_parser::Value;
use std::collections::BTreeMap;

let value = Value::Obj(BTreeMap::new());
value.unwrap_str(); // <-- panics

Unwraps the Obj from the Value::Obj

Panics

If the variant was Value::Str

Examples

use keyvalues_parser::Value;
use std::collections::BTreeMap;

let empty_map = BTreeMap::new();
let value = Value::Obj(empty_map.clone());
assert_eq!(value.unwrap_obj(), empty_map);
use keyvalues_parser::Value;
use std::borrow::Cow;

let value = Value::Str(Cow::from("D'Oh"));
value.unwrap_obj(); // <-- panics

Refer to Value::unwrap_str. Same situation, but with a custom message

Refer to Value::unwrap_obj. Same situation, but with a custom message

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.