Skip to content

Commit ea6ffa6

Browse files
authored
feat(trogon-std): expose uuid v7 generator (#133)
Signed-off-by: Yordis Prieto <yordis.prieto@gmail.com>
1 parent fd78260 commit ea6ffa6

6 files changed

Lines changed: 36 additions & 0 deletions

File tree

rsworkspace/AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Always use `enum` over booleans in the edges such as HTTP, gRPC, Databases, etc,
2+

rsworkspace/Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rsworkspace/crates/AGENTS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
Prefer domain-specific value objects over primitives (e.g. `AcpPrefix` not `String`). Each type's factory must guarantee correctness at construction—invalid instances should be unrepresentable. Validate per-type, not per-aggregate: avoid validating unrelated fields together in a single constructor.
22

3+
Untrusted input must use distinct `*Input` / `*Wire` / `*Request` types. Convert those boundary types into domain types exactly once. After conversion, domain values must be valid forever. Do not add `validate_foo(...)` helpers over a supposed domain struct; if a struct still needs a validator to be safe, it is not a domain type yet. Persist only validated domain types to storage, events, and runtime state. Never persist wire/input types.
4+
35
Every value object lives in its own file named after the type (e.g. `acp_prefix.rs`, `ext_method_name.rs`, `session_id.rs`). Never inline a value object into a config, aggregate, or service file. File layout: `src/{type_snake_case}.rs`; export in `lib.rs` as `pub use {module}::{Type, TypeError}`.
46

57
Errors must be typed—use structs or enums, never `String` or `format!()`. Every error type must implement `Display` and `std::error::Error`. Never discard error context by converting a typed error into a string; wrap the source error as a field or variant instead.

rsworkspace/crates/trogon-std/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ workspace = true
99
[features]
1010
test-support = []
1111
clap = ["dep:clap"]
12+
uuid = ["dep:uuid"]
1213
telemetry-http = [
1314
"dep:axum",
1415
"dep:opentelemetry",
@@ -29,6 +30,7 @@ serde_json = { workspace = true }
2930
tower-http = { workspace = true, optional = true }
3031
tracing = { workspace = true, optional = true }
3132
tracing-opentelemetry = { workspace = true, optional = true }
33+
uuid = { workspace = true, optional = true }
3234

3335
[dev-dependencies]
3436
tokio = { workspace = true, features = ["macros", "rt-multi-thread"] }

rsworkspace/crates/trogon-std/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ pub mod secret_string;
4141
#[cfg(feature = "telemetry-http")]
4242
pub mod telemetry;
4343
pub mod time;
44+
#[cfg(feature = "uuid")]
45+
pub mod uuid;
4446

4547
#[cfg(all(feature = "clap", not(coverage)))]
4648
pub use args::CliArgs;
@@ -57,3 +59,5 @@ pub use json::FailNextSerialize;
5759
pub use json::{JsonSerialize, StdJsonSerialize};
5860
pub use secret_string::{EmptySecret, SecretString};
5961
pub use time::{EpochClock, GetElapsed, GetNow, SystemClock};
62+
#[cfg(feature = "uuid")]
63+
pub use uuid::{NowV7, UuidV7Generator};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use uuid::Uuid;
2+
3+
pub trait NowV7 {
4+
fn now_v7(&self) -> Uuid;
5+
}
6+
7+
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
8+
pub struct UuidV7Generator;
9+
10+
impl NowV7 for UuidV7Generator {
11+
fn now_v7(&self) -> Uuid {
12+
Uuid::now_v7()
13+
}
14+
}
15+
16+
#[cfg(test)]
17+
mod tests {
18+
use super::{NowV7, UuidV7Generator};
19+
20+
#[test]
21+
fn v7_generator_produces_version_7_uuids() {
22+
let uuid = UuidV7Generator.now_v7();
23+
assert_eq!(uuid.get_version_num(), 7);
24+
}
25+
}

0 commit comments

Comments
 (0)