Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ease generating an Id from any Uuid #9

Merged
merged 1 commit into from
Nov 21, 2024
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
ease generating an Id from any Uuid
With a From<Uuid> implementation.

Also update uuid to a more recent version.
  • Loading branch information
Canop committed Nov 7, 2024
commit d14bac3e381534457417ffa643eaa639c1865088
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ serde = { optional = true, version = "1.0", features = ["derive"] }
serde_json = { optional = true, version = "1.0" }
sqlx = { optional = true, version = "0.7", default-features = false, features = ["macros", "runtime-async-std-rustls", "postgres", "chrono", "json", "uuid"] }
utoipa = { optional = true, version = "4.2" }
uuid = { version = "1.7", features = ["v4"] }
uuid = { version = "1.11", features = ["v4"] }

[dev-dependencies]
rstest = "0.18"
Expand Down
7 changes: 7 additions & 0 deletions src/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,13 @@ impl<O: Identifiable> Id<O> {
}
}

/// Make an Id from any valid Uuid
impl<O: Identifiable> From<Uuid> for Id<O> {
fn from(uuid: Uuid) -> Self {
Self::unchecked(uuid)
}
}

/// Parse an Id from its public representation, checking the class
impl<O: Identifiable> FromStr for Id<O> {
type Err = IdError;
Expand Down