• Home
  • Raw
  • Download

Lines Matching full:uuid

2 // Copyright 2018 The Uuid Project Developers.
14 //! Provides support for Universally Unique Identifiers (UUIDs). A UUID is a
20 //! disparate areas, such as databases and network protocols. Typically a UUID
34 //! * `v1` - adds the [`Uuid::new_v1`] function and the ability to create a V1
37 //! * `v3` - adds the [`Uuid::new_v3`] function and the ability to create a V3
38 //! UUID based on the MD5 hash of some data.
39 //! * `v4` - adds the [`Uuid::new_v4`] function and the ability to randomly
40 //! generate a UUID.
41 //! * `v5` - adds the [`Uuid::new_v5`] function and the ability to create a V5
42 //! UUID based on the SHA1 hash of some data.
43 //! * `serde` - adds the ability to serialize and deserialize a UUID using the
52 //! By default, `uuid` can be depended on with:
56 //! uuid = "0.8"
63 //! uuid = { version = "0.8", features = ["serde", "v4"] }
70 //! uuid = { version = "0.8", default-features = false }
75 //! To parse a UUID given in the simple format and print it as a urn:
78 //! use uuid::Uuid;
80 //! fn main() -> Result<(), uuid::Error> {
82 //! Uuid::parse_str("936DA01F9ABD4d9d80C702AF85C822A8")?;
88 //! To create a new random (V4) UUID and print it out in hexadecimal form:
91 //! // Note that this requires the `v4` feature enabled in the uuid crate.
93 //! use uuid::Uuid;
97 //! let my_uuid = Uuid::new_v4()?;
110 //! * urn: `urn:uuid:F9168C5E-CEB2-4faa-B6BF-329BF39FA1E4`
115 //! * [RFC4122: A Universally Unique IDentifier (UUID) URN Namespace](http://tools.ietf.org/html/rf…
120 //! [`Uuid`]: struct.Uuid.html
121 //! [`Uuid::new_v1`]: struct.Uuid.html#method.new_v1
122 //! [`Uuid::new_v3`]: struct.Uuid.html#method.new_v3
123 //! [`Uuid::new_v4`]: struct.Uuid.html#method.new_v4
124 //! [`Uuid::new_v5`]: struct.Uuid.html#method.new_v5
133 html_root_url = "https://docs.rs/uuid/0.8.2"
202 /// A builder struct for creating a UUID.
206 /// Creating a v4 UUID from externally generated bytes:
209 /// use uuid::{Builder, Variant, Version};
216 /// let uuid = Builder::from_bytes(random_bytes)
228 /// The version of the UUID, denoting the generating algorithm.
231 /// Special case for `nil` UUID.
258 /// A Universally Unique Identifier (UUID).
261 pub struct Uuid(Bytes); struct
263 impl Uuid { impl
264 /// UUID namespace for Domain Name System (DNS).
265 pub const NAMESPACE_DNS: Self = Uuid([
270 /// UUID namespace for ISO Object Identifiers (OIDs).
271 pub const NAMESPACE_OID: Self = Uuid([
276 /// UUID namespace for Uniform Resource Locators (URLs).
277 pub const NAMESPACE_URL: Self = Uuid([
282 /// UUID namespace for X.500 Distinguished Names (DNs).
283 pub const NAMESPACE_X500: Self = Uuid([
288 /// Returns the variant of the UUID structure.
290 /// This determines the interpretation of the structure of the UUID.
304 /// Returns the version number of the UUID.
319 /// Returns the version of the UUID.
335 /// Returns the four field values of the UUID in big-endian order.
338 /// original `Uuid` back.
348 /// the UUID version, and for V1 UUIDs, the last 12 bits represent the
352 /// UUID variant, and for V1 UUIDs, the next 13-15 bits indicate the clock
358 /// use uuid::Uuid;
360 /// fn main() -> Result<(), uuid::Error> {
361 /// let uuid = Uuid::nil();
362 /// assert_eq!(uuid.as_fields(), (0, 0, 0, &[0u8; 8]));
364 /// let uuid = Uuid::parse_str("936DA01F-9ABD-4D9D-80C7-02AF85C822A8")?;
366 /// uuid.as_fields(),
395 /// Returns the four field values of the UUID in little-endian order.
403 /// use uuid::Uuid;
405 /// fn main() -> Result<(), uuid::Error> {
406 /// let uuid = Uuid::parse_str("936DA01F-9ABD-4D9D-80C7-02AF85C822A8")?;
408 /// uuid.to_fields_le(),
436 /// Returns a 128bit value containing the UUID data.
438 /// The bytes in the UUID will be packed into a `u128`, like the
439 /// [`Uuid::as_bytes`] method.
444 /// use uuid::Uuid;
446 /// fn main() -> Result<(), uuid::Error> {
447 /// let uuid = Uuid::parse_str("936DA01F-9ABD-4D9D-80C7-02AF85C822A8")?;
449 /// uuid.as_u128(),
474 /// Returns a 128bit little-endian value containing the UUID data.
476 /// The bytes in the UUID will be reversed and packed into a `u128`.
478 /// [`Uuid::to_fields_le`], because the entire UUID is reversed, rather
484 /// use uuid::Uuid;
486 /// fn main() -> Result<(), uuid::Error> {
487 /// let uuid = Uuid::parse_str("936DA01F-9ABD-4D9D-80C7-02AF85C822A8")?;
490 /// uuid.to_u128_le(),
515 /// Returns an array of 16 octets containing the UUID data.
520 /// Tests if the UUID is nil.
531 /// use uuid::Uuid;
533 /// let uuid = Uuid::nil();
536 /// uuid.to_simple().encode_lower(&mut Uuid::encode_buffer()),
541 /// uuid.to_hyphenated()
542 /// .encode_lower(&mut Uuid::encode_buffer()),
547 /// uuid.to_urn().encode_lower(&mut Uuid::encode_buffer()),
548 /// "urn:uuid:00000000-0000-0000-0000-000000000000"
556 impl fmt::Debug for Uuid { implementation
563 impl fmt::Display for Uuid { implementation
580 impl fmt::LowerHex for Uuid { implementation
586 impl fmt::UpperHex for Uuid { implementation
593 impl str::FromStr for Uuid { implementation
597 Uuid::parse_str(uuid_str) in from_str()
601 impl Default for Uuid { implementation
604 Uuid::nil() in default()
639 let default_uuid = Uuid::default(); in test_uuid_default()
640 let nil_uuid = Uuid::nil(); in test_uuid_default()
649 let uuid = test_util::new(); in test_uuid_display() localVariable
650 let s = uuid.to_string(); in test_uuid_display()
653 assert_eq!(s, uuid.to_hyphenated().to_string()); in test_uuid_display()
655 check!(buffer, "{}", uuid, 36, |c| c.is_lowercase() in test_uuid_display()
665 let uuid = test_util::new(); in test_uuid_lowerhex() localVariable
667 check!(buffer, "{:x}", uuid, 36, |c| c.is_lowercase() in test_uuid_lowerhex()
693 let uuid = test_util::new(); in test_uuid_to_string() localVariable
694 let s = uuid.to_string(); in test_uuid_to_string()
709 let uuid = test_util::new(); in test_uuid_upperhex() localVariable
711 check!(buffer, "{:X}", uuid, 36, |c| c.is_uppercase() in test_uuid_upperhex()
718 let nil = Uuid::nil(); in test_nil()
720 let from_bytes = Uuid::from_bytes([ in test_nil()
736 Uuid::NAMESPACE_DNS.to_hyphenated().to_string(), in test_predefined_namespaces()
740 Uuid::NAMESPACE_URL.to_hyphenated().to_string(), in test_predefined_namespaces()
744 Uuid::NAMESPACE_OID.to_hyphenated().to_string(), in test_predefined_namespaces()
748 Uuid::NAMESPACE_X500.to_hyphenated().to_string(), in test_predefined_namespaces()
756 let uuid = in test_get_version_v3() localVariable
757 Uuid::new_v3(&Uuid::NAMESPACE_DNS, "rust-lang.org".as_bytes()); in test_get_version_v3()
759 assert_eq!(uuid.get_version().unwrap(), Version::Md5); in test_get_version_v3()
760 assert_eq!(uuid.get_version_num(), 3); in test_get_version_v3()
767 Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000").unwrap(); in test_get_variant()
769 Uuid::parse_str("67e55044-10b1-426f-9247-bb680e5fe0c8").unwrap(); in test_get_variant()
771 Uuid::parse_str("936DA01F9ABD4d9dC0C702AF85C822A8").unwrap(); in test_get_variant()
773 Uuid::parse_str("F9168C5E-CEB2-4faa-D6BF-329BF39FA1E4").unwrap(); in test_get_variant()
775 Uuid::parse_str("f81d4fae-7dec-11d0-7765-00a0c91e6bf6").unwrap(); in test_get_variant()
841 assert!(ss.starts_with("urn:uuid:")); in test_to_urn_string()
860 let uuid = test_util::new(); in test_string_roundtrip() localVariable
862 let hs = uuid.to_hyphenated().to_string(); in test_string_roundtrip()
863 let uuid_hs = Uuid::parse_str(&hs).unwrap(); in test_string_roundtrip()
864 assert_eq!(uuid_hs, uuid); in test_string_roundtrip()
866 let ss = uuid.to_string(); in test_string_roundtrip()
867 let uuid_ss = Uuid::parse_str(&ss).unwrap(); in test_string_roundtrip()
868 assert_eq!(uuid_ss, uuid); in test_string_roundtrip()
878 let u = Uuid::from_fields(d1, d2, d3, &d4).unwrap(); in test_from_fields()
892 let u = Uuid::from_fields_le(d1, d2, d3, &d4).unwrap(); in test_from_fields_le()
918 let u = Uuid::from_fields(d1_in, d2_in, d3_in, d4_in).unwrap(); in test_fields_roundtrip()
934 let u = Uuid::from_fields_le(d1_in, d2_in, d3_in, d4_in).unwrap(); in test_fields_le_roundtrip()
950 let u = Uuid::from_fields(d1_in, d2_in, d3_in, d4_in).unwrap(); in test_fields_le_are_actually_le()
963 let u = Uuid::from_u128(v_in); in test_from_u128()
974 let u = Uuid::from_u128_le(v_in); in test_from_u128_le()
985 let u = Uuid::from_u128(v_in); in test_u128_roundtrip()
995 let u = Uuid::from_u128_le(v_in); in test_u128_le_roundtrip()
1005 let u = Uuid::from_u128(v_in); in test_u128_le_is_actually_le()
1018 let u = Uuid::from_slice(&b).unwrap(); in test_from_slice()
1031 let u = Uuid::from_bytes(b); in test_from_bytes()
1053 let u = Uuid::from_slice(&b_in).unwrap(); in test_bytes_roundtrip()