Skip to content

elide-dev/uuid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

elide-uuid

Maven Central CI Kotlin Kotlin Kotlin/JS. IR supported Contributor Covenant Reliability Maintainability Security Vulnerabilities Bugs FOSSA Status OpenSSF Best Practices

K/N UUID. This brings a UUID that matches UUIDs on various platforms:

  • iOS/Mac: NSUUID
  • Java: java.util.UUID
  • Native: Source implementation

Features

  • Adheres to RFC4122
  • Support for uuid3, uuid4, and uuid5
  • 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

Setup

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>")
}

Usage

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"}

"Zero-overhead" abstraction

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.

Serialization

Both JVM serialization and KotlinX serialization are supported out of the box.

Contributing

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.

Additional checks

Quality gate

FOSSA Status

This is a fork

Ben Asher's original library is here.

About Elide

This library is part of a larger polyglot framework and runtime called Elide. You can learn more about Elide at elide.dev.