Rusty Value

This crate adds a RustyValue trait that can be derived for all types (except unions) to create a generic value that represents a rust value. This can be used to implement serialization of types without having to rely on serde.

Usage

The trait RustyValue allows one to create a rusty_value::Value for any type that implements it. This trait can be derived if the derive feature is enabled.

```rust use rusty_value::*;

[derive(RustyValue)]

struct MyStruct { foo: String, bar: u8, }

fn main() { let value = MyStruct { foo: "Hello World".tostring(), bar: 12, }.intorusty_value();

match value { Value::Primitive(p) => match p { rustyvalue::Primitive::Integer() => println!("is an integer"), rustyvalue::Primitive::Float() => println!("is a float"), rustyvalue::Primitive::String() => println!("is a string"), rustyvalue::Primitive::OsString() => println!("is a os string"), rustyvalue::Primitive::Char() => println!("is a char"), rustyvalue::Primitive::Bool() => println!("is a boolean"), }, Value::Struct(s) => println!("is a struct with name {}", s.name), Value::Enum(e) => println!("is an enum with name {} of variant {}", e.name, e.variant), Value::Map() => println!("is a map"), Value::List() => println!("is a list"), Value::None => println!("is none"), } } ```

Converting a type into a rusty value cannot fail as rusty_value::RustyValue is able to represent any safe rust data type. The trait RustyValue is already implemented for most std types and can therefore be easily derived.