Sign in

    #Moonbit/Core UUID

    #Overview

    The @uuid package provides an implementation of the Universally Unique IDentifier per RFC 4122.

    Currently, @uuid does not assume any random generation; you'll have to bring your own random bytes to construct UUIDs.

    #Usage

    Construct a version 4 UUID:

    ///|
    test {
    let u = @uuid.from_hex("ddf99703-742f-7505-4c54-df36a9c243fe").as_version(V4)
    inspect(u.to_string(), content="ddf99703-742f-4505-8c54-df36a9c243fe")
    }

    You can then use it as a key in mappings as it's immutable and implemented Hash, Eq (and Compare for b-tree).

    UUID

    type UUID derive(Compare, Eq)

    UUID that complies with RFC 4122.

    UUID objects are immutable, hashable and usable as mapping keys. The Display of UUIDs is like 12345678-1234-1234-1234-123456789abc; UUIDs can be constructed using such strings, or 16-bytes strings with big- endian byte order.

    Usage

    test {
    let u1 = @uuid.from_hex("ddf99703-742f-7505-4c54-df36a9c243fe")
    let u2 = @uuid.from_bytes(
    Bytes::from_array([
    221, 249, 151, 3, 116, 47, 117, 5, 76, 84, 223, 54, 169, 194, 67, 254,
    ]),
    )
    assert_eq(u1, u2)
    }

    Construct an RFC-4122-compliant v4 UUID:

    test {
    let _u = @uuid.from_hex("9558cfadb48547c70f9adf1f75cdef29").as_version(V4)
    }

    impl Show for UUID
    impl ToJson for UUID
    impl FromJson for UUID

    UUID::as_version

    fn UUID::as_version(self : UUID, version : Version) -> UUID

    Converts this UUID to RFC-4122 with the given version number.

    UUID::compare

    #deprecated("`UUID::compare` is deprecated, use `Compare::compare` instead.")
    fn UUID::compare(UUID, UUID) -> Int

    UUID::equal

    #deprecated("`UUID::equal` is deprecated, use `Eq::equal` instead.")
    fn UUID::equal(UUID, UUID) -> Bool

    UUID::from_json

    #deprecated("`UUID::from_json` is deprecated, use `@moonbitlang/core/json.FromJson::from_json` instead.")
    fn UUID::from_json(json : Json, path :
    JsonPath
    ) -> UUID raise
    JsonDecodeError

    UUID::hash

    fn UUID::hash(self : UUID) -> Int

    UUID::not_equal

    #deprecated("`UUID::not_equal` is deprecated, use `Eq::not_equal` instead.")
    fn UUID::not_equal(x : UUID, y : UUID) -> Bool

    UUID::op_ge

    #deprecated("`UUID::op_ge` is deprecated, use `Compare::op_ge` instead.")
    fn UUID::op_ge(x : UUID, y : UUID) -> Bool

    UUID::op_gt

    #deprecated("`UUID::op_gt` is deprecated, use `Compare::op_gt` instead.")
    fn UUID::op_gt(x : UUID, y : UUID) -> Bool

    UUID::op_le

    #deprecated("`UUID::op_le` is deprecated, use `Compare::op_le` instead.")
    fn UUID::op_le(x : UUID, y : UUID) -> Bool

    UUID::op_lt

    #deprecated("`UUID::op_lt` is deprecated, use `Compare::op_lt` instead.")
    fn UUID::op_lt(x : UUID, y : UUID) -> Bool

    UUID::output

    #deprecated("`UUID::output` is deprecated, use `Show::output` instead.")
    fn UUID::output(self : UUID, logger : &Logger) -> Unit

    UUID::to_bytes

    fn UUID::to_bytes(self : UUID) -> Bytes

    The UUID as a 16-byte string.

    UUID::to_json

    #deprecated("`UUID::to_json` is deprecated, use `ToJson::to_json` instead.")
    fn UUID::to_json(self : UUID) -> Json

    UUID::to_repr

    #deprecated("`UUID::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn UUID::to_repr(self : UUID) ->
    Repr

    UUID::to_string

    fn UUID::to_string(self : UUID) -> String

    UUID::variant

    fn UUID::variant(self : UUID) -> Variant

    Retrieves the variant of the UUID.

    UUID::version

    fn UUID::version(self : UUID) -> Version?

    Retrieves the version number of the UUID.

    If the variant of the UUID is not RFC4122, returns None.

    Variant

    pub(all) enum Variant {
    ReservedNCS
    RFC4122(Version)
    ReservedMicrosoft
    ReservedFuture
    } derive(
    Debug
    )

    The UUID variant.

    Variant::to_repr

    #deprecated("`Variant::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn Variant::to_repr(Variant) ->
    Repr

    Version

    pub(all) enum Version {
    V1
    V2
    V3
    V4
    V5
    Unknown(Int)
    } derive(
    Debug
    )

    The UUID version number.

    This is only used when the variant is RFC4122.

    Version::to_repr

    #deprecated("`Version::to_repr` is deprecated, use `@moonbitlang/core/debug.Debug::to_repr` instead.")
    fn Version::to_repr(Version) ->
    Repr

    from_bytes

    fn from_bytes(bytes : Bytes) -> UUID raise

    Constructs a UUID with the given big-endian bytes.

    The produced UUID is not RFC-4122 compliant; see also as_version().

    from_hex

    fn from_hex(hex : String) -> UUID raise

    Constructs a UUID with the given hexadecimal string.

    This function ignores dashes (-) in the given string. The remaining letters must be exactly 32 hexadecimals, or an error will be raised.

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io