Skip to main content

Value

Enum Value 

Source
pub enum Value {
    Null,
    Bool(bool),
    String(String),
    Integer(i64),
    Float(f64),
    Array(Vec<Value>),
    Map(Vec<(String, Value)>),
}
Expand description

Represents a unified configuration value.

This enum provides a common representation for values from different configuration formats (JSON, YAML, TOML, etc.).

§Examples

use bare_config::value::Value;

let value = Value::String("hello".to_string());
assert!(value.is_string());

let value = Value::integer(42);
assert!(value.is_number());

Variants§

§

Null

Null value (JSON null, YAML null, etc.)

§

Bool(bool)

Boolean value (true or false)

§

String(String)

String value

§

Integer(i64)

Integer number value

§

Float(f64)

Floating-point number value

§

Array(Vec<Value>)

Array value

§

Map(Vec<(String, Value)>)

Object/value map (JSON object, YAML mapping, etc.)

Implementations§

Source§

impl Value

Source

pub fn null() -> Self

Creates a new Null value.

§Examples
use bare_config::value::Value;

let value = Value::null();
assert!(value.is_null());
Source

pub fn bool(b: bool) -> Self

Creates a new Boolean value.

§Examples
use bare_config::value::Value;

let value = Value::bool(true);
assert_eq!(value.as_bool(), Some(true));
Source

pub fn string<S: Into<String>>(s: S) -> Self

Creates a new String value.

§Examples
use bare_config::value::Value;

let value = Value::string("hello");
assert_eq!(value.as_str(), Some("hello"));
Source

pub fn integer(i: i64) -> Self

Creates a new Integer value.

§Examples
use bare_config::value::Value;

let value = Value::integer(42);
assert_eq!(value.as_integer(), Some(42));
Source

pub fn float(f: f64) -> Self

Creates a new Float value.

§Examples
use bare_config::value::Value;

let value = Value::float(3.14);
assert_eq!(value.as_float(), Some(3.14));
Source

pub fn array(v: Vec<Value>) -> Self

Creates a new Array value.

§Examples
use bare_config::value::Value;

let value = Value::array(vec![
    Value::integer(1),
    Value::integer(2),
]);
assert!(value.is_array());
Source

pub fn map(m: Vec<(String, Value)>) -> Self

Creates a new Map value.

§Examples
use bare_config::value::Value;

let value = Value::map(vec![
    ("key".to_string(), Value::string("value".to_string())),
]);
assert!(value.is_map());
Source

pub fn is_null(&self) -> bool

Returns true if this value is Null.

§Examples
use bare_config::value::Value;

let value = Value::null();
assert!(value.is_null());

let value = Value::string("test");
assert!(!value.is_null());
Source

pub fn is_bool(&self) -> bool

Returns true if this value is a Boolean.

§Examples
use bare_config::value::Value;

let value = Value::bool(true);
assert!(value.is_bool());
Source

pub fn is_string(&self) -> bool

Returns true if this value is a String.

§Examples
use bare_config::value::Value;

let value = Value::string("test");
assert!(value.is_string());
Source

pub fn is_number(&self) -> bool

Returns true if this value is a Number (Integer or Float).

§Examples
use bare_config::value::Value;

let value = Value::integer(42);
assert!(value.is_number());

let value = Value::float(3.14);
assert!(value.is_number());
Source

pub fn is_integer(&self) -> bool

Returns true if this value is an Integer.

§Examples
use bare_config::value::Value;

let value = Value::integer(42);
assert!(value.is_integer());
Source

pub fn is_float(&self) -> bool

Returns true if this value is a Float.

§Examples
use bare_config::value::Value;

let value = Value::float(3.14);
assert!(value.is_float());
Source

pub fn is_array(&self) -> bool

Returns true if this value is an Array.

§Examples
use bare_config::value::Value;

let value = Value::array(vec![]);
assert!(value.is_array());
Source

pub fn is_map(&self) -> bool

Returns true if this value is a Map.

§Examples
use bare_config::value::Value;

let value = Value::map(vec![]);
assert!(value.is_map());
Source

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

Returns the Boolean value if this is a Boolean.

§Examples
use bare_config::value::Value;

let value = Value::bool(true);
assert_eq!(value.as_bool(), Some(true));
Source

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

Returns the String value if this is a String.

§Examples
use bare_config::value::Value;

let value = Value::string("hello");
assert_eq!(value.as_str(), Some("hello"));
Source

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

Returns the Integer value if this is an Integer.

§Examples
use bare_config::value::Value;

let value = Value::integer(42);
assert_eq!(value.as_integer(), Some(42));
Source

pub fn as_u16(&self) -> Option<u16>

Returns the value as u16 if this is an Integer value within range.

Unlike to_u16, this method only works on Integer values and does not attempt to parse strings.

Source

pub fn to_u16(&self) -> Option<u16>

Attempts to convert this value into u16.

This accepts integer values directly and parses string values. Unlike as_u16, this also works on String values.

Source

pub fn as_u16_or(&self, default: u16) -> u16

Returns u16 value or a caller-provided default.

Source

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

Returns the Float value if this is a Float.

§Examples
use bare_config::value::Value;

let value = Value::float(3.14);
assert_eq!(value.as_float(), Some(3.14));
Source

pub fn as_array(&self) -> Option<&Vec<Value>>

Returns the Array value if this is an Array.

§Examples
use bare_config::value::Value;

let value = Value::array(vec![Value::integer(1)]);
let arr = value.as_array().unwrap();
assert_eq!(arr.len(), 1);
Source

pub fn as_map(&self) -> Option<&Vec<(String, Value)>>

Returns the Map value if this is a Map.

§Examples
use bare_config::value::Value;

let value = Value::map(vec![("key".to_string(), Value::string("value".to_string()))]);
let map = value.as_map().unwrap();
assert_eq!(map.len(), 1);
Source

pub fn len(&self) -> usize

Returns the number of elements in this value.

For Array, returns the number of elements. For Map, returns the number of key-value pairs. For other types, returns 0.

§Examples
use bare_config::value::Value;

let value = Value::array(vec![Value::integer(1), Value::integer(2)]);
assert_eq!(value.len(), 2);
Source

pub fn is_empty(&self) -> bool

Returns true if this value has no elements.

§Examples
use bare_config::value::Value;

let value = Value::array(vec![]);
assert!(value.is_empty());
Source

pub fn to_string_repr(&self) -> String

Converts the value to a string representation.

§Examples
use bare_config::value::Value;

let value = Value::string("hello");
assert_eq!(value.to_string_repr(), "hello");

let value = Value::integer(42);
assert_eq!(value.to_string_repr(), "42");

Trait Implementations§

Source§

impl Clone for Value

Source§

fn clone(&self) -> Value

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Value

Source§

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

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

impl Default for Value

Source§

fn default() -> Value

Returns the “default value” for a type. Read more
Source§

impl From<&str> for Value

Source§

fn from(s: &str) -> Self

Converts to this type from the input type.
Source§

impl<K, V> From<HashMap<K, V>> for Value
where K: Into<String>, V: Into<Value>,

Source§

fn from(m: HashMap<K, V>) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Value

Source§

fn from(s: String) -> Self

Converts to this type from the input type.
Source§

impl From<Value> for Value

Source§

fn from(value: Value) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for Value
where T: Into<Value>,

Source§

fn from(v: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl From<bool> for Value

Source§

fn from(b: bool) -> Self

Converts to this type from the input type.
Source§

impl From<f32> for Value

Source§

fn from(f: f32) -> Self

Converts to this type from the input type.
Source§

impl From<f64> for Value

Source§

fn from(f: f64) -> Self

Converts to this type from the input type.
Source§

impl From<i16> for Value

Source§

fn from(i: i16) -> Self

Converts to this type from the input type.
Source§

impl From<i32> for Value

Source§

fn from(i: i32) -> Self

Converts to this type from the input type.
Source§

impl From<i64> for Value

Source§

fn from(i: i64) -> Self

Converts to this type from the input type.
Source§

impl From<i8> for Value

Source§

fn from(i: i8) -> Self

Converts to this type from the input type.
Source§

impl From<isize> for Value

Source§

fn from(i: isize) -> Self

Converts to this type from the input type.
Source§

impl From<u16> for Value

Source§

fn from(i: u16) -> Self

Converts to this type from the input type.
Source§

impl From<u32> for Value

Source§

fn from(i: u32) -> Self

Converts to this type from the input type.
Source§

impl From<u64> for Value

Source§

fn from(i: u64) -> Self

Converts to this type from the input type.
Source§

impl From<u8> for Value

Source§

fn from(i: u8) -> Self

Converts to this type from the input type.
Source§

impl From<usize> for Value

Source§

fn from(i: usize) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Value

Source§

fn eq(&self, other: &Value) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl TryFrom<Value> for Value

Source§

type Error = ConfigError

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

fn try_from(json: JsonValue) -> ConfigResult<Self>

Performs the conversion.
Source§

impl StructuralPartialEq for Value

Auto Trait Implementations§

§

impl Freeze for Value

§

impl RefUnwindSafe for Value

§

impl Send for Value

§

impl Sync for Value

§

impl Unpin for Value

§

impl UnsafeUnpin for Value

§

impl UnwindSafe for Value

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.