K/N UUID. This brings a UUID that matches UUIDs on various platforms:
- iOS/Mac:
NSUUID
- Java:
java.util.UUID
- Native: Source implementation
- Adheres to RFC4122
- Support for
uuid3
,uuid4
, anduuid5
- Frozen and thread-safe (thread-safe randomness in native)
- Tested on all platforms, and against macOS/iOS UUID to verify correctness
- Aggressively optimized for performance and safety
- Updated for new versions of Kotlin
- Zero dependencies (only
stdlib
) - 🆕 All Kotlin targets, including WASM/WASI and Android/Native
- 🆕 Serializable on JVM
- 🆕 Serializable with KotlinX
- 🆕 Zero-overhead model
In your build.gradle(.kts)
:
dependencies {
implementation("dev.elide:elide-uuid:<version>")
}
From an Elide application:
dependencies {
implementation(elide.uuid)
}
To enable KotlinX Serialization support:
dependencies {
implementation("dev.elide:elide-uuid-kotlinx:<version>")
}
From any Kotlin source set:
val uuid = uuid4()
println(uuid.toString())
// 1b4e28ba-2fa1-11d2-883f-0016d3cca427
When KotlinX Serialization support is included:
@Serializable data class Sample(
@Serializable(with = UUIDSerializer::class) val uuid: Uuid,
)
val sample = Sample(uuid = uuid4())
println(Json.encodeToString(Sample.serializer(), uuid.toString()))
// {"uuid": "1b4e28ba-2fa1-11d2-883f-0016d3cca427"}
This library is designed to offer a compile-time option for dealing with UUIDs; internally, UUIDs are stored as a simple
Pair<Long, Long>
to minimize allocations, and the main Uuid
class is a @JvmInline value class
.
Thus, your UUIDs are strictly typed and validated but also remain very lightweight.
The main UUID library uses exactly zero dependencies, and even omits a stdlib
dependency by default. You must bring
your own before shipping a target with this library.
Both JVM serialization and KotlinX serialization are supported out of the box.
Contributions are welcome! Once you file a PR, a bot will as you to sign the CLA (Contributor License Agreement) and to sign off your commits to establish your DCO (Developer Certificate of Origin).
Checks run automatically on each PR. Review is requested automatically once your PR goes from draft to open.
Ben Asher's original library is here.
This library is part of a larger polyglot framework and runtime called Elide. You can learn more about Elide at elide.dev
.