Skip to content
Merged
Show file tree
Hide file tree
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
Binary file added .DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
52 changes: 46 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,55 @@
[workspace.package]
# name = "rust-tagged"
[package]
name = "rust-tagged"
version = "0.1.0"
edition = "2024"
authors = ["Codefonsi <info@codefonsi.com>"]
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"]
File renamed without changes.
7 changes: 7 additions & 0 deletions examples/basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use tagged_core::{Tagged};

struct UserIdTag;
fn main() {
let id = Tagged::<u32, UserIdTag>::new(42);
println!("Tagged value is = {}", id.value());
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub mod rust_tagged{
pub use tagged_core::*;
}
File renamed without changes.
File renamed without changes.
Binary file added tagged-core/.DS_Store
Binary file not shown.
6 changes: 3 additions & 3 deletions crates/tagged-core/Cargo.toml → tagged-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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 <info@codefonsi.com>"]
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]
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rust_tagged::{Tagged};
use tagged_core::{Tagged};

struct UserIdTag;
fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rust_tagged::Tagged;
use tagged_core::Tagged;

struct Employee {
id: Tagged<i32, Self>,
Expand Down
25 changes: 25 additions & 0 deletions crates/tagged-core/src/lib.rs → tagged-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<String, EmailTag>;
///
/// 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<T, U> {
value: T,
_marker: std::marker::PhantomData<U>,
Expand Down
Binary file added tagged-macros/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.