From e9fe95a89346e6e634064c937d3b883c34938e08 Mon Sep 17 00:00:00 2001 From: trivernis Date: Wed, 5 Oct 2022 16:07:17 +0200 Subject: [PATCH] Add example usage to README Signed-off-by: trivernis --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79ceef7..dcc2984 100644 --- a/README.md +++ b/README.md @@ -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"), + } } ```