#[non_exhaustive]pub enum Value<'a> {
Show 25 variants
Bool(bool),
Char(char),
F32(f32),
F64(f64),
I8(i8),
I16(i16),
I32(i32),
I64(i64),
I128(i128),
Isize(isize),
String(&'a str),
U8(u8),
U16(u16),
U32(u32),
U64(u64),
U128(u128),
Usize(usize),
Path(&'a Path),
Error(&'a (dyn Error + 'static)),
Listable(&'a dyn Listable),
Mappable(&'a dyn Mappable),
Structable(&'a dyn Structable),
Enumerable(&'a dyn Enumerable),
Tuplable(&'a dyn Tuplable),
Unit,
}
Expand description
Any Rust value
The Value
enum is used to pass single values to the
visitor. Primitive types are enumerated and other types
are represented at trait objects.
Values are converted to Value
instances using
Valuable::as_value()
.
§Examples
Convert a primitive type
use valuable::{Value, Valuable};
let num = 123;
let val = num.as_value();
assert!(matches!(val, Value::I32(v) if v == 123));
Converting a struct
use valuable::{Value, Valuable};
#[derive(Valuable, Debug)]
struct HelloWorld {
message: String,
}
let hello = HelloWorld {
message: "greetings".to_string(),
};
let val = hello.as_value();
assert!(matches!(val, Value::Structable(_v)));
// The Value `Debug` output matches the struct's
assert_eq!(
format!("{:?}", val),
format!("{:?}", hello),
);
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Bool(bool)
Char(char)
F32(f32)
F64(f64)
I8(i8)
I16(i16)
I32(i32)
I64(i64)
I128(i128)
Isize(isize)
String(&'a str)
U8(u8)
U16(u16)
U32(u32)
U64(u64)
U128(u128)
Usize(usize)
Path(&'a Path)
std
only.A Rust &Path
value
§Examples
use valuable::Value;
use std::path::Path;
let path = Path::new("a.txt");
let v = Value::Path(path);
Error(&'a (dyn Error + 'static))
std
only.A Rust error value
§Examples
use valuable::Value;
use std::io;
let err: io::Error = io::ErrorKind::Other.into();
let v = Value::Error(&err);
Listable(&'a dyn Listable)
A Rust list value
§Examples
use valuable::Value;
let vals = vec![1, 2, 3, 4, 5];
let v = Value::Listable(&vals);
Mappable(&'a dyn Mappable)
A Rust map value
§Examples
use valuable::Value;
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert("foo", 1);
map.insert("bar", 2);
let v = Value::Mappable(&map);
Structable(&'a dyn Structable)
A Rust struct value
§Examples
use valuable::{Value, Valuable};
#[derive(Valuable)]
struct MyStruct {
field: u32,
}
let my_struct = MyStruct {
field: 123,
};
let v = Value::Structable(&my_struct);
Enumerable(&'a dyn Enumerable)
A Rust enum value
§Examples
use valuable::{Value, Valuable};
#[derive(Valuable)]
enum MyEnum {
Foo,
Bar,
}
let my_enum = MyEnum::Foo;
let v = Value::Enumerable(&my_enum);
Tuplable(&'a dyn Tuplable)
A tuple value
§Examples
use valuable::{Value, Valuable};
let my_tuple = (123, 456);
let v = Value::Tuplable(&my_tuple);
Unit
Implementations§
Source§impl<'a> Value<'a>
impl<'a> Value<'a>
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Return a bool
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::Bool(true).as_bool(), Some(true));
assert_eq!(Value::Char('c').as_bool(), None);
Sourcepub fn as_char(&self) -> Option<char>
pub fn as_char(&self) -> Option<char>
Return a char
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::Char('c').as_char(), Some('c'));
assert_eq!(Value::Bool(true).as_char(), None);
Sourcepub fn as_f32(&self) -> Option<f32>
pub fn as_f32(&self) -> Option<f32>
Return a f32
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::F32(3.1415).as_f32(), Some(3.1415));
assert_eq!(Value::Bool(true).as_f32(), None);
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Return a f64
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::F64(3.1415).as_f64(), Some(3.1415));
assert_eq!(Value::Bool(true).as_f64(), None);
Sourcepub fn as_i8(&self) -> Option<i8>
pub fn as_i8(&self) -> Option<i8>
Return a i8
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::I8(42).as_i8(), Some(42));
assert_eq!(Value::I32(42).as_i8(), Some(42));
assert_eq!(Value::I64(i64::MAX).as_i8(), None);
assert_eq!(Value::Bool(true).as_i8(), None);
Sourcepub fn as_i16(&self) -> Option<i16>
pub fn as_i16(&self) -> Option<i16>
Return a i16
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::I16(42).as_i16(), Some(42));
assert_eq!(Value::I32(42).as_i16(), Some(42));
assert_eq!(Value::I64(i64::MAX).as_i16(), None);
assert_eq!(Value::Bool(true).as_i16(), None);
Sourcepub fn as_i32(&self) -> Option<i32>
pub fn as_i32(&self) -> Option<i32>
Return a i32
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::I32(42).as_i32(), Some(42));
assert_eq!(Value::I64(42).as_i32(), Some(42));
assert_eq!(Value::I64(i64::MAX).as_i32(), None);
assert_eq!(Value::Bool(true).as_i32(), None);
Sourcepub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Return a i64
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::I64(42).as_i64(), Some(42));
assert_eq!(Value::I128(42).as_i64(), Some(42));
assert_eq!(Value::I128(i128::MAX).as_i64(), None);
assert_eq!(Value::Bool(true).as_i64(), None);
Sourcepub fn as_i128(&self) -> Option<i128>
pub fn as_i128(&self) -> Option<i128>
Return a i128
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::I128(42).as_i128(), Some(42));
assert_eq!(Value::U128(42).as_i128(), Some(42));
assert_eq!(Value::U128(u128::MAX).as_i128(), None);
assert_eq!(Value::Bool(true).as_i128(), None);
Sourcepub fn as_isize(&self) -> Option<isize>
pub fn as_isize(&self) -> Option<isize>
Return a isize
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::Isize(42).as_isize(), Some(42));
assert_eq!(Value::Usize(42).as_isize(), Some(42));
assert_eq!(Value::Usize(usize::MAX).as_isize(), None);
assert_eq!(Value::Bool(true).as_isize(), None);
Sourcepub fn as_u8(&self) -> Option<u8>
pub fn as_u8(&self) -> Option<u8>
Return a u8
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::U8(42).as_u8(), Some(42));
assert_eq!(Value::U32(42).as_u8(), Some(42));
assert_eq!(Value::U32(u32::MAX).as_u8(), None);
assert_eq!(Value::Bool(true).as_u8(), None);
Sourcepub fn as_u16(&self) -> Option<u16>
pub fn as_u16(&self) -> Option<u16>
Return a u16
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::U16(42).as_u16(), Some(42));
assert_eq!(Value::U32(42).as_u16(), Some(42));
assert_eq!(Value::U32(u32::MAX).as_u16(), None);
assert_eq!(Value::Bool(true).as_u16(), None);
Sourcepub fn as_u32(&self) -> Option<u32>
pub fn as_u32(&self) -> Option<u32>
Return a u32
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::U32(42).as_u32(), Some(42));
assert_eq!(Value::U64(42).as_u32(), Some(42));
assert_eq!(Value::U64(u64::MAX).as_u32(), None);
assert_eq!(Value::Bool(true).as_u32(), None);
Sourcepub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Return a u64
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::U64(42).as_u64(), Some(42));
assert_eq!(Value::U128(42).as_u64(), Some(42));
assert_eq!(Value::U128(u128::MAX).as_u64(), None);
assert_eq!(Value::Bool(true).as_u64(), None);
Sourcepub fn as_u128(&self) -> Option<u128>
pub fn as_u128(&self) -> Option<u128>
Return a u128
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::U128(42).as_u128(), Some(42));
assert_eq!(Value::I32(42).as_u128(), Some(42));
assert_eq!(Value::I32(-5).as_u128(), None);
assert_eq!(Value::Bool(true).as_u128(), None);
Sourcepub fn as_usize(&self) -> Option<usize>
pub fn as_usize(&self) -> Option<usize>
Return a usize
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::Usize(42).as_usize(), Some(42));
assert_eq!(Value::I8(42).as_usize(), Some(42));
assert_eq!(Value::I8(-5).as_usize(), None);
assert_eq!(Value::Bool(true).as_usize(), None);
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Return a &str
representation of self
, if possible.
§Examples
use valuable::Value;
assert_eq!(Value::String("hello").as_str(), Some("hello"));
assert_eq!(Value::Bool(true).as_str(), None);
Sourcepub fn as_path(&self) -> Option<&Path>
Available on crate feature std
only.
pub fn as_path(&self) -> Option<&Path>
std
only.Return a &Path
representation of self
, if possible.
§Examples
use valuable::Value;
use std::path::Path;
let path = Path::new("a.txt");
assert!(Value::Path(path).as_path().is_some());
assert!(Value::Bool(true).as_path().is_none());
Sourcepub fn as_error(&self) -> Option<&(dyn Error + 'static)>
Available on crate feature std
only.
pub fn as_error(&self) -> Option<&(dyn Error + 'static)>
std
only.Return a &dyn Error
representation of self
, if possible.
§Examples
use valuable::Value;
use std::io;
let err: io::Error = io::ErrorKind::Other.into();
assert!(Value::Error(&err).as_error().is_some());
assert!(Value::Bool(true).as_error().is_none());
Sourcepub fn as_listable(&self) -> Option<&dyn Listable>
pub fn as_listable(&self) -> Option<&dyn Listable>
Return a &dyn Listable
representation of self
, if possible.
§Examples
use valuable::Value;
let list = vec![1, 2, 3, 4];
assert!(Value::Listable(&list).as_listable().is_some());
assert!(Value::Bool(true).as_listable().is_none());
Sourcepub fn as_mappable(&self) -> Option<&dyn Mappable>
pub fn as_mappable(&self) -> Option<&dyn Mappable>
Return a &dyn Mappable
representation of self
, if possible.
§Examples
use valuable::Value;
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert("foo", 123);
map.insert("bar", 456);
assert!(Value::Mappable(&map).as_mappable().is_some());
assert!(Value::Bool(true).as_mappable().is_none());
Sourcepub fn as_structable(&self) -> Option<&dyn Structable>
pub fn as_structable(&self) -> Option<&dyn Structable>
Return a &dyn Structable
representation of self
, if possible.
§Examples
use valuable::{Value, Valuable};
#[derive(Valuable)]
struct Hello {
message: &'static str,
}
let hello = Hello { message: "Hello world" };
assert!(Value::Structable(&hello).as_structable().is_some());
assert!(Value::Bool(true).as_structable().is_none());
Sourcepub fn as_enumerable(&self) -> Option<&dyn Enumerable>
pub fn as_enumerable(&self) -> Option<&dyn Enumerable>
Return a &dyn Enumerable
representation of self
, if possible.
§Examples
use valuable::{Value, Valuable};
#[derive(Valuable)]
enum Greet {
Hello,
World,
}
let greet = Greet::Hello;
assert!(Value::Enumerable(&greet).as_enumerable().is_some());
assert!(Value::Bool(true).as_enumerable().is_none());
Sourcepub fn as_tuplable(&self) -> Option<&dyn Tuplable>
pub fn as_tuplable(&self) -> Option<&dyn Tuplable>
Return a &dyn Tuplable
representation of self
, if possible.
§Examples
use valuable::Value;
let my_tuple = (123, 456);
assert!(Value::Tuplable(&my_tuple).as_tuplable().is_some());
assert!(Value::Bool(true).as_tuplable().is_none());
Trait Implementations§
Source§impl<'a> From<&'a Path> for Value<'a>
Available on crate feature std
only.A Rust &Path
value
impl<'a> From<&'a Path> for Value<'a>
std
only.A Rust &Path
value
§Examples
use valuable::Value;
use std::path::Path;
let path = Path::new("a.txt");
let v = Value::Path(path);
Source§impl<'a> From<&'a dyn Enumerable> for Value<'a>
A Rust enum value
impl<'a> From<&'a dyn Enumerable> for Value<'a>
A Rust enum value
§Examples
use valuable::{Value, Valuable};
#[derive(Valuable)]
enum MyEnum {
Foo,
Bar,
}
let my_enum = MyEnum::Foo;
let v = Value::Enumerable(&my_enum);
Source§fn from(src: &'a dyn Enumerable) -> Value<'a>
fn from(src: &'a dyn Enumerable) -> Value<'a>
Source§impl<'a> From<&'a (dyn Error + 'static)> for Value<'a>
Available on crate feature std
only.A Rust error value
impl<'a> From<&'a (dyn Error + 'static)> for Value<'a>
std
only.A Rust error value
§Examples
use valuable::Value;
use std::io;
let err: io::Error = io::ErrorKind::Other.into();
let v = Value::Error(&err);
Source§impl<'a> From<&'a dyn Listable> for Value<'a>
A Rust list value
impl<'a> From<&'a dyn Listable> for Value<'a>
A Rust list value
§Examples
use valuable::Value;
let vals = vec![1, 2, 3, 4, 5];
let v = Value::Listable(&vals);
Source§impl<'a> From<&'a dyn Mappable> for Value<'a>
A Rust map value
impl<'a> From<&'a dyn Mappable> for Value<'a>
A Rust map value
§Examples
use valuable::Value;
use std::collections::HashMap;
let mut map = HashMap::new();
map.insert("foo", 1);
map.insert("bar", 2);
let v = Value::Mappable(&map);
Source§impl<'a> From<&'a dyn Structable> for Value<'a>
A Rust struct value
impl<'a> From<&'a dyn Structable> for Value<'a>
A Rust struct value
§Examples
use valuable::{Value, Valuable};
#[derive(Valuable)]
struct MyStruct {
field: u32,
}
let my_struct = MyStruct {
field: 123,
};
let v = Value::Structable(&my_struct);
Source§fn from(src: &'a dyn Structable) -> Value<'a>
fn from(src: &'a dyn Structable) -> Value<'a>
Source§impl<'a> From<&'a dyn Tuplable> for Value<'a>
A tuple value
impl<'a> From<&'a dyn Tuplable> for Value<'a>
A tuple value
§Examples
use valuable::{Value, Valuable};
let my_tuple = (123, 456);
let v = Value::Tuplable(&my_tuple);
Source§impl<'a> From<&'a str> for Value<'a>
A Rust &str
value
impl<'a> From<&'a str> for Value<'a>
A Rust &str
value
§Examples
use valuable::Value;
let v = Value::String("hello");
Source§impl<'a> From<bool> for Value<'a>
A Rust bool
value
impl<'a> From<bool> for Value<'a>
A Rust bool
value
§Examples
use valuable::Value;
let v = Value::Bool(true);
Source§impl<'a> From<char> for Value<'a>
A Rust char
value
impl<'a> From<char> for Value<'a>
A Rust char
value
§Examples
use valuable::Value;
let v = Value::Char('h');
Source§impl<'a> From<f32> for Value<'a>
A Rust f32
value
impl<'a> From<f32> for Value<'a>
A Rust f32
value
§Examples
use valuable::Value;
let v = Value::F32(3.1415);
Source§impl<'a> From<f64> for Value<'a>
A Rust f64
value
impl<'a> From<f64> for Value<'a>
A Rust f64
value
§Examples
use valuable::Value;
let v = Value::F64(3.1415);
Source§impl<'a> From<i128> for Value<'a>
A Rust i128
value
impl<'a> From<i128> for Value<'a>
A Rust i128
value
§Examples
use valuable::Value;
let v = Value::I128(42);
Source§impl<'a> From<i16> for Value<'a>
A Rust i16
value
impl<'a> From<i16> for Value<'a>
A Rust i16
value
§Examples
use valuable::Value;
let v = Value::I16(42);
Source§impl<'a> From<i32> for Value<'a>
A Rust i32
value
impl<'a> From<i32> for Value<'a>
A Rust i32
value
§Examples
use valuable::Value;
let v = Value::I32(42);
Source§impl<'a> From<i64> for Value<'a>
A Rust i64
value
impl<'a> From<i64> for Value<'a>
A Rust i64
value
§Examples
use valuable::Value;
let v = Value::I64(42);
Source§impl<'a> From<i8> for Value<'a>
A Rust i8
value
impl<'a> From<i8> for Value<'a>
A Rust i8
value
§Examples
use valuable::Value;
let v = Value::I8(42);
Source§impl<'a> From<isize> for Value<'a>
A Rust isize
value
impl<'a> From<isize> for Value<'a>
A Rust isize
value
§Examples
use valuable::Value;
let v = Value::Isize(42);
Source§impl<'a> From<u128> for Value<'a>
A Rust u128
value
impl<'a> From<u128> for Value<'a>
A Rust u128
value
§Examples
use valuable::Value;
let v = Value::U128(42);
Source§impl<'a> From<u16> for Value<'a>
A Rust u16
value
impl<'a> From<u16> for Value<'a>
A Rust u16
value
§Examples
use valuable::Value;
let v = Value::U16(42);
Source§impl<'a> From<u32> for Value<'a>
A Rust u32
value
impl<'a> From<u32> for Value<'a>
A Rust u32
value
§Examples
use valuable::Value;
let v = Value::U32(42);
Source§impl<'a> From<u64> for Value<'a>
A Rust u64
value
impl<'a> From<u64> for Value<'a>
A Rust u64
value
§Examples
use valuable::Value;
let v = Value::U64(42);
Source§impl<'a> From<u8> for Value<'a>
A Rust u8
value
impl<'a> From<u8> for Value<'a>
A Rust u8
value
§Examples
use valuable::Value;
let v = Value::U8(42);
Source§impl<'a> From<usize> for Value<'a>
A Rust usize
value
impl<'a> From<usize> for Value<'a>
A Rust usize
value
§Examples
use valuable::Value;
let v = Value::Usize(42);