Converts a NonNilUuid back into a Uuid.
let uuid = Uuid::from_u128(0x0123456789abcdef0123456789abcdef);\nlet non_nil = NonNilUuid::try_from(uuid).unwrap();\nlet uuid_again = Uuid::from(non_nil);\n\nassert_eq!(uuid, uuid_again);v to Self.Err(Error::FromValueError(v)) if could not convert v to Self.Err(Error::FromValueError(v)) if v is not convertible to Self.std only.std only.Creates a UUID from four field values.
\nBasic usage:
\n\nlet d1 = 0xa1a2a3a4;\nlet d2 = 0xb1b2;\nlet d3 = 0xc1c2;\nlet d4 = [0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8];\n\nlet uuid = Uuid::from_fields(d1, d2, d3, &d4);\n\nassert_eq!(\n \"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\",\n uuid.hyphenated().to_string(),\n);Creates a UUID from four field values in little-endian order.
\nThe bytes in the d1, d2 and d3 fields will be flipped to convert\ninto big-endian order. This is based on the endianness of the UUID,\nrather than the target environment so bytes will be flipped on both\nbig and little endian machines.
Basic usage:
\n\nlet d1 = 0xa1a2a3a4;\nlet d2 = 0xb1b2;\nlet d3 = 0xc1c2;\nlet d4 = [0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8];\n\nlet uuid = Uuid::from_fields_le(d1, d2, d3, &d4);\n\nassert_eq!(\n \"a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8\",\n uuid.hyphenated().to_string(),\n);Creates a UUID from a 128bit value.
\nBasic usage:
\n\nlet v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128;\n\nlet uuid = Uuid::from_u128(v);\n\nassert_eq!(\n \"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\",\n uuid.hyphenated().to_string(),\n);Creates a UUID from a 128bit value in little-endian order.
\nThe entire value will be flipped to convert into big-endian order.\nThis is based on the endianness of the UUID, rather than the target\nenvironment so bytes will be flipped on both big and little endian\nmachines.
\nBasic usage:
\n\nlet v = 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8u128;\n\nlet uuid = Uuid::from_u128_le(v);\n\nassert_eq!(\n \"d8d7d6d5-d4d3-d2d1-c2c1-b2b1a4a3a2a1\",\n uuid.hyphenated().to_string(),\n);Creates a UUID from two 64bit values.
\nBasic usage:
\n\nlet hi = 0xa1a2a3a4b1b2c1c2u64;\nlet lo = 0xd1d2d3d4d5d6d7d8u64;\n\nlet uuid = Uuid::from_u64_pair(hi, lo);\n\nassert_eq!(\n \"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\",\n uuid.hyphenated().to_string(),\n);Creates a UUID using the supplied bytes.
\nThis function will return an error if b has any length other than 16.
Basic usage:
\n\nlet bytes = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\n\nlet uuid = Uuid::from_slice(&bytes)?;\n\nassert_eq!(\n \"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\",\n uuid.hyphenated().to_string(),\n);Creates a UUID using the supplied bytes in little endian order.
\nThe individual fields encoded in the buffer will be flipped.
\nThis function will return an error if b has any length other than 16.
Basic usage:
\n\nlet bytes = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\n\nlet uuid = Uuid::from_slice_le(&bytes)?;\n\nassert_eq!(\n uuid.hyphenated().to_string(),\n \"a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8\"\n);Creates a UUID using the supplied bytes.
\nBasic usage:
\n\nlet bytes = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\n\nlet uuid = Uuid::from_bytes(bytes);\n\nassert_eq!(\n uuid.hyphenated().to_string(),\n \"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\"\n);Creates a UUID using the supplied bytes in little endian order.
\nNote that ordering is applied to each field, rather than to the bytes as a whole.\nThis ordering is compatible with Microsoft’s mixed endian GUID format.
\nBasic usage:
\n\nlet bytes = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\n\nlet uuid = Uuid::from_bytes_le(bytes);\n\nassert_eq!(\n \"a4a3a2a1-b2b1-c2c1-d1d2-d3d4d5d6d7d8\",\n uuid.hyphenated().to_string(),\n);Creates a reference to a UUID from a reference to the supplied bytes.
\nBasic usage:
\n\nlet bytes = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\n\nlet uuid = Uuid::from_bytes_ref(&bytes);\n\nassert_eq!(\n uuid.hyphenated().to_string(),\n \"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\"\n);\n\nassert!(std::ptr::eq(\n uuid as *const Uuid as *const u8,\n &bytes as *const [u8; 16] as *const u8,\n));Get a Hyphenated formatter.
Get a borrowed Hyphenated formatter.
UUID namespace for Domain Name System (DNS).
\nUUID namespace for ISO Object Identifiers (OIDs).
\nUUID namespace for Uniform Resource Locators (URLs).
\nUUID namespace for X.500 Distinguished Names (DNs).
\nReturns the variant of the UUID structure.
\nThis determines the interpretation of the structure of the UUID.\nThis method simply reads the value of the variant byte. It doesn’t\nvalidate the rest of the UUID as conforming to that variant.
\nBasic usage:
\n\nlet my_uuid = Uuid::parse_str(\"02f09a3f-1624-3b1d-8409-44eff7708208\")?;\n\nassert_eq!(Variant::RFC4122, my_uuid.get_variant());Returns the version number of the UUID.
\nThis represents the algorithm used to generate the value.\nThis method is the future-proof alternative to Uuid::get_version.
Basic usage:
\n\nlet my_uuid = Uuid::parse_str(\"02f09a3f-1624-3b1d-8409-44eff7708208\")?;\n\nassert_eq!(3, my_uuid.get_version_num());Returns the version of the UUID.
\nThis represents the algorithm used to generate the value.\nIf the version field doesn’t contain a recognized version then None\nis returned. If you’re trying to read the version for a future extension\nyou can also use Uuid::get_version_num to unconditionally return a\nnumber. Future extensions may start to return Some once they’re\nstandardized and supported.
Basic usage:
\n\nlet my_uuid = Uuid::parse_str(\"02f09a3f-1624-3b1d-8409-44eff7708208\")?;\n\nassert_eq!(Some(Version::Md5), my_uuid.get_version());Returns the four field values of the UUID.
\nThese values can be passed to the Uuid::from_fields method to get\nthe original Uuid back.
u32 value. For V1 UUIDs, this field\nrepresents the low 32 bits of the timestamp.u16 value. For V1 UUIDs, this field\nrepresents the middle 16 bits of the timestamp.u16 value. The 4 most significant bits give\nthe UUID version, and for V1 UUIDs, the last 12 bits represent the\nhigh 12 bits of the timestamp.let uuid = Uuid::nil();\n\nassert_eq!(uuid.as_fields(), (0, 0, 0, &[0u8; 8]));\n\nlet uuid = Uuid::parse_str(\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\")?;\n\nassert_eq!(\n uuid.as_fields(),\n (\n 0xa1a2a3a4,\n 0xb1b2,\n 0xc1c2,\n &[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8],\n )\n);Returns the four field values of the UUID in little-endian order.
\nThe bytes in the returned integer fields will be converted from\nbig-endian order. This is based on the endianness of the UUID,\nrather than the target environment so bytes will be flipped on both\nbig and little endian machines.
\nuse uuid::Uuid;\n\nlet uuid = Uuid::parse_str(\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\")?;\n\nassert_eq!(\n uuid.to_fields_le(),\n (\n 0xa4a3a2a1,\n 0xb2b1,\n 0xc2c1,\n &[0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8],\n )\n);Returns a 128bit value containing the value.
\nThe bytes in the UUID will be packed directly into a u128.
let uuid = Uuid::parse_str(\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\")?;\n\nassert_eq!(\n uuid.as_u128(),\n 0xa1a2a3a4b1b2c1c2d1d2d3d4d5d6d7d8,\n);Returns a 128bit little-endian value containing the value.
\nThe bytes in the u128 will be flipped to convert into big-endian\norder. This is based on the endianness of the UUID, rather than the\ntarget environment so bytes will be flipped on both big and little\nendian machines.
Note that this will produce a different result than\nUuid::to_fields_le, because the entire UUID is reversed, rather\nthan reversing the individual fields in-place.
let uuid = Uuid::parse_str(\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\")?;\n\nassert_eq!(\n uuid.to_u128_le(),\n 0xd8d7d6d5d4d3d2d1c2c1b2b1a4a3a2a1,\n);Returns two 64bit values containing the value.
\nThe bytes in the UUID will be split into two u64.\nThe first u64 represents the 64 most significant bits,\nthe second one represents the 64 least significant.
let uuid = Uuid::parse_str(\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\")?;\nassert_eq!(\n uuid.as_u64_pair(),\n (0xa1a2a3a4b1b2c1c2, 0xd1d2d3d4d5d6d7d8),\n);Returns a slice of 16 octets containing the value.
\nThis method borrows the underlying byte value of the UUID.
\nlet bytes1 = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\nlet uuid1 = Uuid::from_bytes_ref(&bytes1);\n\nlet bytes2 = uuid1.as_bytes();\nlet uuid2 = Uuid::from_bytes_ref(bytes2);\n\nassert_eq!(uuid1, uuid2);\n\nassert!(std::ptr::eq(\n uuid2 as *const Uuid as *const u8,\n &bytes1 as *const [u8; 16] as *const u8,\n));Consumes self and returns the underlying byte value of the UUID.
\nlet bytes = [\n 0xa1, 0xa2, 0xa3, 0xa4,\n 0xb1, 0xb2,\n 0xc1, 0xc2,\n 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8,\n];\nlet uuid = Uuid::from_bytes(bytes);\nassert_eq!(bytes, uuid.into_bytes());Returns the bytes of the UUID in little-endian order.
\nThe bytes for each field will be flipped to convert into little-endian order.\nThis is based on the endianness of the UUID, rather than the target environment\nso bytes will be flipped on both big and little endian machines.
\nNote that ordering is applied to each field, rather than to the bytes as a whole.\nThis ordering is compatible with Microsoft’s mixed endian GUID format.
\nuse uuid::Uuid;\n\nlet uuid = Uuid::parse_str(\"a1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8\")?;\n\nassert_eq!(\n uuid.to_bytes_le(),\n ([\n 0xa4, 0xa3, 0xa2, 0xa1, 0xb2, 0xb1, 0xc2, 0xc1, 0xd1, 0xd2,\n 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8\n ])\n);A buffer that can be used for encode_... calls, that is\nguaranteed to be long enough for any of the format adapters.
let uuid = Uuid::nil();\n\nassert_eq!(\n uuid.simple().encode_lower(&mut Uuid::encode_buffer()),\n \"00000000000000000000000000000000\"\n);\n\nassert_eq!(\n uuid.hyphenated()\n .encode_lower(&mut Uuid::encode_buffer()),\n \"00000000-0000-0000-0000-000000000000\"\n);\n\nassert_eq!(\n uuid.urn().encode_lower(&mut Uuid::encode_buffer()),\n \"urn:uuid:00000000-0000-0000-0000-000000000000\"\n);If the UUID is the correct version (v1, v6, or v7) this will return\nthe timestamp in a version-agnostic Timestamp. For other versions\nthis will return None.
This method is unlikely to roundtrip a timestamp in a UUID due to the way\nUUIDs encode timestamps. The timestamp returned from this method will be truncated to\n100ns precision for version 1 and 6 UUIDs, and to millisecond precision for version 7 UUIDs.
\nIf the UUID is the correct version (v1, or v6) this will return the\nnode value as a 6-byte array. For other versions this will return None.
Parses a Uuid from a string of hexadecimal digits with optional\nhyphens.
Any of the formats generated by this module (simple, hyphenated, urn,\nMicrosoft GUID) are supported by this parsing function.
\nPrefer try_parse unless you need detailed user-facing diagnostics.\nThis method will be eventually deprecated in favor of try_parse.
Parse a hyphenated UUID:
\n\nlet uuid = Uuid::parse_str(\"550e8400-e29b-41d4-a716-446655440000\")?;\n\nassert_eq!(Some(Version::Random), uuid.get_version());\nassert_eq!(Variant::RFC4122, uuid.get_variant());Parses a Uuid from a string of hexadecimal digits with optional\nhyphens.
This function is similar to parse_str, in fact parse_str shares\nthe same underlying parser. The difference is that if try_parse\nfails, it won’t generate very useful error messages. The parse_str\nfunction will eventually be deprecated in favor of try_parse.
To parse a UUID from a byte stream instead of a UTF8 string, see\ntry_parse_ascii.
Parse a hyphenated UUID:
\n\nlet uuid = Uuid::try_parse(\"550e8400-e29b-41d4-a716-446655440000\")?;\n\nassert_eq!(Some(Version::Random), uuid.get_version());\nassert_eq!(Variant::RFC4122, uuid.get_variant());Parses a Uuid from a string of hexadecimal digits with optional\nhyphens.
The input is expected to be a string of ASCII characters. This method\ncan be more convenient than try_parse if the UUID is being\nparsed from a byte stream instead of from a UTF8 string.
Parse a hyphenated UUID:
\n\nlet uuid = Uuid::try_parse_ascii(b\"550e8400-e29b-41d4-a716-446655440000\")?;\n\nassert_eq!(Some(Version::Random), uuid.get_version());\nassert_eq!(Variant::RFC4122, uuid.get_variant());Creates a random UUID.
\nThis uses the getrandom crate to utilise the operating system’s RNG\nas the source of random numbers. If you’d like to use a custom\ngenerator, don’t use this method: generate random bytes using your\ncustom generator and pass them to the\nuuid::Builder::from_random_bytes function\ninstead.
Note that usage of this method requires the v4 feature of this crate\nto be enabled.
Basic usage:
\n\nlet uuid = Uuid::new_v4();\n\nassert_eq!(Some(Version::Random), uuid.get_version());Create a new version 7 UUID using the current time value.
\nThis method is a convenient alternative to Uuid::new_v7 that uses the current system time\nas the source timestamp. All UUIDs generated through this method by the same process are\nguaranteed to be ordered by their creation.
Create a new version 7 UUID using a time value and random bytes.
\nWhen the std feature is enabled, you can also use Uuid::now_v7.
Note that usage of this method requires the v7 feature of this crate\nto be enabled.
Also see Uuid::now_v7 for a convenient way to generate version 7\nUUIDs using the current system time.
A v7 UUID can be created from a unix Timestamp plus a 128 bit\nrandom number. When supplied as such, the data will be combined\nto ensure uniqueness and sortability at millisecond granularity.
let ts = Timestamp::from_unix(NoContext, 1497624119, 1234);\n\nlet uuid = Uuid::new_v7(ts);\n\nassert!(\n uuid.hyphenated().to_string().starts_with(\"015cb15a-86d8-7\")\n);A v7 UUID can also be created with a counter to ensure batches of\nUUIDs created together remain sortable:
\n\nlet context = ContextV7::new();\nlet uuid1 = Uuid::new_v7(Timestamp::from_unix(&context, 1497624119, 1234));\nlet uuid2 = Uuid::new_v7(Timestamp::from_unix(&context, 1497624119, 1234));\n\nassert!(uuid1 < uuid2);