From df4faec9488a18ee204c2e1857d701a676370ccb Mon Sep 17 00:00:00 2001 From: Akash soni <33283321+akashsoni01@users.noreply.github.com> Date: Wed, 2 Jul 2025 00:49:12 +0530 Subject: [PATCH] #18 --- examples/floating_points.rs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 examples/floating_points.rs diff --git a/examples/floating_points.rs b/examples/floating_points.rs new file mode 100644 index 0000000..aacda76 --- /dev/null +++ b/examples/floating_points.rs @@ -0,0 +1,31 @@ +use serde::{Deserialize, Serialize}; + +fn main() { + use tagged_core::Tagged; + #[derive(Clone, Hash, Debug, PartialEq, Eq, Serialize, Deserialize)] + struct SomeCustomType { + some_id: String + } + #[derive(Clone, Hash, Debug, PartialEq, Eq, Serialize, Deserialize)] + struct SomeCustomType2(String); + #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] + struct User { + id: Tagged, + id2: SomeCustomType, + id3: SomeCustomType2, + } + + let user = User { id: 0.0.into() , id2: SomeCustomType { some_id: "2".into() }, id3: SomeCustomType2("3".into())}; + let j = serde_json::to_string(&user).unwrap(); + println!("{}", j); +} + +/* +Problem with normal types +{"id":"1","id2":{"some_id":"2"}} + +// rust is powerful enough to solve it using touple +{"id":"1","id2":{"some_id":"2"},"id3":"3"} + +// or we can use a new type called tagged that don't need a new name. +*/ \ No newline at end of file