diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..c5db90b Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index 736992f..2ceade0 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,7 @@ target/ # These are backup files generated by rustfmt **/*.rs.bk - +**/*.DS_Store # MSVC Windows builds of rustc generate these, which store debugging information *.pdb diff --git a/Cargo.toml b/Cargo.toml index b7a0891..4163c61 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,15 +1,55 @@ -[workspace.package] -# name = "rust-tagged" +[package] +name = "rust-tagged" version = "0.1.0" edition = "2024" authors = ["Codefonsi "] -license = "Mozilla Public License 2.0" +license = "MPL-2.0" +description = "A lightweight tagged type abstraction for type-safe IDs, etc." +repository = "https://github.com/codefonsi/rust-tagged" +homepage = "https://github.com/codefonsi/rust-tagged" +documentation = "https://docs.rs/rust-tagged" +keywords = ["tagged", "id", "type-safe", "newtype", "tagged-union"] +categories = ["data-structures"] +readme = "./README.md" +include = ["src/**/*", "Cargo.toml", "../../README.md", "LICENSE"] [workspace] resolver = "3" # or "3" members = [ - "crates/tagged-chrono", - "crates/tagged-core", - "crates/tagged-macros", + "tagged-chrono", + "tagged-core", + "tagged-macros", ] + +#[lib] +#path = "crates/tagged-core/src/lib.rs" + +#[workspace.dependencies] +#tagged-core = {path = "crates/tagged-core"} +# + +[patch.crates-io] +tagged-core = { path = "tagged-core" } + +[dependencies] +tagged-core = { version = "0.1.0" } # This will use the patched version from local + +[workspace.dependencies] +#tagged-core = { path = "crates/tagged-core", version = "0.1.0" } +#serde = { version = "1.0", optional = true, features = ["derive"] } +#uuid = { version = "1.4", optional = true } +#chrono = { version = "0.4", optional = true } + +#[dependencies] +#tagged-core.workspace = true +#serde = { version = "1.0", features = ["derive"] } +#uuid = { version = "1.4" } +#chrono = { version = "0.4" } + +# crates/tagged-core/Cargo.toml +[features] +default = [] +#serde = ["dep:serde"] +#uuid = ["dep:uuid"] +#chrono = ["dep:chrono"] diff --git a/crates/benches/proc_macro_bench.rs b/benches/proc_macro_bench.rs similarity index 100% rename from crates/benches/proc_macro_bench.rs rename to benches/proc_macro_bench.rs diff --git a/examples/basic.rs b/examples/basic.rs new file mode 100644 index 0000000..3bcbccd --- /dev/null +++ b/examples/basic.rs @@ -0,0 +1,7 @@ +use tagged_core::{Tagged}; + +struct UserIdTag; +fn main() { + let id = Tagged::::new(42); + println!("Tagged value is = {}", id.value()); +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..d0730d9 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,3 @@ +pub mod rust_tagged{ + pub use tagged_core::*; +} \ No newline at end of file diff --git a/crates/tagged-chrono/Cargo.toml b/tagged-chrono/Cargo.toml similarity index 100% rename from crates/tagged-chrono/Cargo.toml rename to tagged-chrono/Cargo.toml diff --git a/crates/tagged-chrono/src/lib.rs b/tagged-chrono/src/lib.rs similarity index 100% rename from crates/tagged-chrono/src/lib.rs rename to tagged-chrono/src/lib.rs diff --git a/tagged-core/.DS_Store b/tagged-core/.DS_Store new file mode 100644 index 0000000..d20629e Binary files /dev/null and b/tagged-core/.DS_Store differ diff --git a/crates/tagged-core/Cargo.toml b/tagged-core/Cargo.toml similarity index 87% rename from crates/tagged-core/Cargo.toml rename to tagged-core/Cargo.toml index c200a45..09a201c 100644 --- a/crates/tagged-core/Cargo.toml +++ b/tagged-core/Cargo.toml @@ -1,16 +1,16 @@ [package] -name = "rust-tagged" +name = "tagged-core" version = "0.1.0" edition = "2024" description = "A lightweight tagged type abstraction for type-safe IDs, etc." -license = "Mozila-2.0" +license = "MPL-2.0" authors = ["Codefonsi "] repository = "https://github.com/akashsoni01/rust-tagged" homepage = "https://github.com/akashsoni01/rust-tagged" documentation = "https://docs.rs/rust-tagged" keywords = ["tagged", "id", "type-safe", "newtype", "tagged-union"] categories = ["data-structures"] -readme = "../../README.md" +readme = "../README.md" include = ["src/**/*", "Cargo.toml", "../../README.md", "LICENSE"] [dependencies] diff --git a/crates/tagged-core/examples/basic.rs b/tagged-core/examples/basic.rs similarity index 82% rename from crates/tagged-core/examples/basic.rs rename to tagged-core/examples/basic.rs index 76b3658..c392e3f 100644 --- a/crates/tagged-core/examples/basic.rs +++ b/tagged-core/examples/basic.rs @@ -1,4 +1,4 @@ -use rust_tagged::{Tagged}; +use tagged_core::{Tagged}; struct UserIdTag; fn main() { diff --git a/crates/tagged-core/examples/robust_types_problem.rs b/tagged-core/examples/robust_types_problem.rs similarity index 100% rename from crates/tagged-core/examples/robust_types_problem.rs rename to tagged-core/examples/robust_types_problem.rs diff --git a/crates/tagged-core/examples/robust_types_solution.rs b/tagged-core/examples/robust_types_solution.rs similarity index 98% rename from crates/tagged-core/examples/robust_types_solution.rs rename to tagged-core/examples/robust_types_solution.rs index eb12481..7a9841b 100644 --- a/crates/tagged-core/examples/robust_types_solution.rs +++ b/tagged-core/examples/robust_types_solution.rs @@ -1,4 +1,4 @@ -use rust_tagged::Tagged; +use tagged_core::Tagged; struct Employee { id: Tagged, diff --git a/crates/tagged-core/src/lib.rs b/tagged-core/src/lib.rs similarity index 66% rename from crates/tagged-core/src/lib.rs rename to tagged-core/src/lib.rs index a582515..aaaf002 100644 --- a/crates/tagged-core/src/lib.rs +++ b/tagged-core/src/lib.rs @@ -1,4 +1,29 @@ use std::ops::Deref; +/// 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. +/// +/// Eliminate accidental mixups between similar types (e.g. OrgId vs UserId) +/// Enforce domain modeling in code via the type system +/// Ergonomic .into() support for primitive conversions +/// +/// # Example +/// +/// ``` +/// use rust_tagged::{Tagged}; +/// +/// #[derive(Debug)] +/// struct EmailTag; +/// +/// type Email = Tagged; +/// +/// fn main() { +/// let email: Email = "test@example.com".into(); +/// println!("Email inner value: {}", email.value()); +/// +/// // Convert back to String +/// let raw: String = email.into(); +/// println!("Raw String: {raw}"); +/// } +/// ``` pub struct Tagged { value: T, _marker: std::marker::PhantomData, diff --git a/tagged-macros/.DS_Store b/tagged-macros/.DS_Store new file mode 100644 index 0000000..1271304 Binary files /dev/null and b/tagged-macros/.DS_Store differ diff --git a/crates/tagged-macros/Cargo.toml b/tagged-macros/Cargo.toml similarity index 100% rename from crates/tagged-macros/Cargo.toml rename to tagged-macros/Cargo.toml diff --git a/crates/tagged-macros/examples/basic.rs b/tagged-macros/examples/basic.rs similarity index 100% rename from crates/tagged-macros/examples/basic.rs rename to tagged-macros/examples/basic.rs diff --git a/crates/tagged-macros/src/lib.rs b/tagged-macros/src/lib.rs similarity index 100% rename from crates/tagged-macros/src/lib.rs rename to tagged-macros/src/lib.rs