Skip to content
Merged

#18 #23

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions examples/floating_points.rs
Original file line number Diff line number Diff line change
@@ -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<f32, Self>,
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.
*/