|
1 | | -/// rust-tagged provides a simple way to define strongly typed wrappers over primitive types like String, i32, Uuid, chrono::DateTime, etc. It helps eliminate bugs caused by misusing raw primitives for conceptually distinct fields such as UserId, Email, ProductId, and more. |
2 | | -/// |
3 | | -/// Eliminate accidental mixups between similar types (e.g. OrgId vs UserId) |
4 | | -/// Enforce domain modeling in code via the type system |
5 | | -/// Ergonomic .into() support for primitive conversions |
6 | | -/// |
7 | | -/// # Example - Simple |
8 | | -/// |
9 | | -/// ``` |
10 | | -/// use tagged_core::{Tagged}; |
11 | | -/// |
12 | | -/// #[derive(Debug)] |
13 | | -/// struct EmailTag; |
14 | | -/// |
15 | | -/// type Email = Tagged<String, EmailTag>; |
16 | | -/// |
17 | | -/// fn main() { |
18 | | -/// let email: Email = "test@example.com".into(); |
19 | | -/// println!("Email inner value: {}", email.value()); |
20 | | -/// |
21 | | -/// // Convert back to String |
22 | | -/// let raw: String = email.into(); |
23 | | -/// println!("Raw String: {raw}"); |
24 | | -/// } |
25 | | -/// ``` |
26 | | -/// |
27 | | -/// # Example - Debug |
28 | | -/// ``` |
29 | | -/// use tagged_core::Tagged; |
30 | | -/// |
31 | | -/// |
32 | | -/// #[derive(Debug)] |
33 | | -/// struct UserIdTag { |
34 | | -/// a: Tagged<u32, Self>, |
35 | | -/// b: Tagged<u32, Self>, |
36 | | -/// } |
37 | | -/// |
38 | | -/// |
39 | | -/// fn main() { |
40 | | -/// let instance = UserIdTag{a: 1.into(), b: 2.into()}; |
41 | | -/// |
42 | | -/// println!("{}", instance.a); |
43 | | -/// println!("{:?}", instance.b); |
44 | | -/// } |
45 | | -/// ``` |
46 | | -/// |
47 | | -/// # Example - Hash |
48 | | -/// ``` |
49 | | -/// fn main() { |
50 | | -/// use tagged_core::Tagged; |
51 | | -/// use std::collections::HashSet; |
52 | | -/// |
53 | | -/// #[derive(Clone, Hash, Debug, PartialEq, Eq)] |
54 | | -/// struct User { |
55 | | -/// id: Tagged<String, Self> |
56 | | -/// } |
57 | | -/// let mut s: HashSet<User> = HashSet::new(); |
58 | | -/// let user = User{id: "me@example.com".into()}; |
59 | | -/// s.insert(user.clone()); |
60 | | -/// |
61 | | -/// assert!(s.contains(&user)); |
62 | | -/// } |
63 | | -/// ``` |
64 | | -/// |
65 | | -/// # Example - Iter |
66 | | -/// ``` |
67 | | -/// use tagged_core::Tagged; |
68 | | -/// |
69 | | -/// #[derive(Debug)] |
70 | | -/// struct Org; |
71 | | -/// |
72 | | -/// type EmployeeNames = Tagged<Vec<String>, Org>; |
73 | | -/// |
74 | | -/// fn main() { |
75 | | -/// let names: EmployeeNames = Tagged::new(vec!["Alice".into(), "Bob".into()]); |
76 | | -/// |
77 | | -/// for name in &names { |
78 | | -/// println!("Name: {name}"); |
79 | | -/// } |
80 | | -/// |
81 | | -/// // Consuming iterator |
82 | | -/// for name in names { |
83 | | -/// println!("Owned: {name}"); |
84 | | -/// } |
85 | | -/// } |
86 | | -/// |
87 | | -/// /* |
88 | | -/// Name: Alice |
89 | | -/// Name: Bob |
90 | | -/// Owned: Alice |
91 | | -/// Owned: Bob |
92 | | -/// */ |
93 | | -/// ``` |
94 | | -/// |
95 | | -/// # Example - Mutation |
96 | | -/// ``` |
97 | | -/// use tagged_core::Tagged; |
98 | | -/// |
99 | | -/// #[derive(Debug)] |
100 | | -/// struct Org; |
101 | | -/// |
102 | | -/// type OrgName = Tagged<String, Org>; |
103 | | -/// |
104 | | -/// fn main() { |
105 | | -/// let mut name = OrgName::new("Codefonsi".into()); |
106 | | -/// |
107 | | -/// name.set("New Org Name".into()); |
108 | | -/// |
109 | | -/// println!("Updated Org Name: {}", name.value()); |
110 | | -/// } |
111 | | -/// ``` |
112 | | -
|
113 | 1 | pub use tagged_core::*; |
0 commit comments