Add example usage to README

Signed-off-by: trivernis <trivernis@protonmail.com>
main
trivernis 2 years ago
parent 2f71f66e9e
commit e9fe95a893
Signed by: Trivernis
GPG Key ID: DFFFCC2C7A02DB45

@ -13,7 +13,7 @@ type that implements it. This trait can be derived if the `derive` **feature** i
```rust
use rusty_value::RustyValue;
use rusty_value::{RustyValue, Value};
#[derive(RustyValue)]
struct MyStruct {
@ -22,10 +22,26 @@ struct MyStruct {
}
fn main() {
MyStruct {
let value = MyStruct {
foo: "Hello World".to_string(),
bar: 12,
}.into_rusty_value();
match value {
Value::Primitive(p) => match p {
rusty_value::Primitive::Integer(_) => println!("is an integer"),
rusty_value::Primitive::Float(_) => println!("is a float"),
rusty_value::Primitive::String(_) => println!("is a string"),
rusty_value::Primitive::OsString(_) => println!("is a os string"),
rusty_value::Primitive::Char(_) => println!("is a char"),
rusty_value::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"),
}
}
```

Loading…
Cancel
Save