• Home
  • Raw
  • Download

Lines Matching full:uuid

2 // Copyright 2018 The Uuid Project Developers.
16 Uuid, Variant,
19 impl std::fmt::Debug for Uuid { implementation
26 impl fmt::Display for Uuid { implementation
43 impl fmt::LowerHex for Uuid { implementation
49 impl fmt::UpperHex for Uuid { implementation
56 /// Format a [`Uuid`] as a hyphenated string, like
60 pub struct Hyphenated(Uuid);
62 /// Format a [`Uuid`] as a simple string, like
66 pub struct Simple(Uuid);
68 /// Format a [`Uuid`] as a URN string, like
69 /// `urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8`.
72 pub struct Urn(Uuid);
74 /// Format a [`Uuid`] as a braced hyphenated string, like
78 pub struct Braced(Uuid);
80 impl Uuid { implementation
90 // SAFETY: `Uuid` and `Hyphenated` have the same ABI in as_hyphenated()
91 unsafe { &*(self as *const Uuid as *const Hyphenated) } in as_hyphenated() constant
103 // SAFETY: `Uuid` and `Simple` have the same ABI in as_simple()
104 unsafe { &*(self as *const Uuid as *const Simple) } in as_simple() constant
116 // SAFETY: `Uuid` and `Urn` have the same ABI in as_urn()
117 unsafe { &*(self as *const Uuid as *const Urn) } in as_urn() constant
129 // SAFETY: `Uuid` and `Braced` have the same ABI in as_braced()
130 unsafe { &*(self as *const Uuid as *const Braced) } in as_braced() constant
227 buf[..9].copy_from_slice(b"urn:uuid:");
240 /// The length of a hyphenated [`Uuid`] string.
242 /// [`Uuid`]: ../struct.Uuid.html
245 /// Creates a [`Hyphenated`] from a [`Uuid`].
247 /// [`Uuid`]: ../struct.Uuid.html
249 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
250 Hyphenated(uuid) in from_uuid()
253 /// Writes the [`Uuid`] as a lower-case hyphenated string to
255 /// encoded UUID.
261 /// [`Uuid`]: ../struct.Uuid.html
266 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
270 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
275 /// use uuid::Uuid;
277 /// fn main() -> Result<(), uuid::Error> {
278 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
282 /// uuid.hyphenated()
283 /// .encode_lower(&mut Uuid::encode_buffer()),
289 /// uuid.hyphenated().encode_lower(&mut buf);
304 /// Writes the [`Uuid`] as an upper-case hyphenated string to
306 /// encoded UUID.
312 /// [`Uuid`]: ../struct.Uuid.html
317 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
321 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
326 /// use uuid::Uuid;
328 /// fn main() -> Result<(), uuid::Error> {
329 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
333 /// uuid.hyphenated()
334 /// .encode_upper(&mut Uuid::encode_buffer()),
340 /// uuid.hyphenated().encode_upper(&mut buf);
355 /// Get a reference to the underlying [`Uuid`].
360 /// use uuid::Uuid;
362 /// let hyphenated = Uuid::nil().hyphenated();
363 /// assert_eq!(*hyphenated.as_uuid(), Uuid::nil());
365 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
369 /// Consumes the [`Hyphenated`], returning the underlying [`Uuid`].
374 /// use uuid::Uuid;
376 /// let hyphenated = Uuid::nil().hyphenated();
377 /// assert_eq!(hyphenated.into_uuid(), Uuid::nil());
379 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
385 /// The length of a braced [`Uuid`] string.
387 /// [`Uuid`]: ../struct.Uuid.html
390 /// Creates a [`Braced`] from a [`Uuid`].
392 /// [`Uuid`]: ../struct.Uuid.html
394 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
395 Braced(uuid) in from_uuid()
398 /// Writes the [`Uuid`] as a lower-case hyphenated string surrounded by
400 /// the encoded UUID.
406 /// [`Uuid`]: ../struct.Uuid.html
411 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
415 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
420 /// use uuid::Uuid;
422 /// fn main() -> Result<(), uuid::Error> {
423 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
427 /// uuid.braced()
428 /// .encode_lower(&mut Uuid::encode_buffer()),
434 /// uuid.braced().encode_lower(&mut buf);
449 /// Writes the [`Uuid`] as an upper-case hyphenated string surrounded by
451 /// the encoded UUID.
457 /// [`Uuid`]: ../struct.Uuid.html
462 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
466 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
471 /// use uuid::Uuid;
473 /// fn main() -> Result<(), uuid::Error> {
474 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
478 /// uuid.braced()
479 /// .encode_upper(&mut Uuid::encode_buffer()),
485 /// uuid.braced().encode_upper(&mut buf);
500 /// Get a reference to the underlying [`Uuid`].
505 /// use uuid::Uuid;
507 /// let braced = Uuid::nil().braced();
508 /// assert_eq!(*braced.as_uuid(), Uuid::nil());
510 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
514 /// Consumes the [`Braced`], returning the underlying [`Uuid`].
519 /// use uuid::Uuid;
521 /// let braced = Uuid::nil().braced();
522 /// assert_eq!(braced.into_uuid(), Uuid::nil());
524 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
530 /// The length of a simple [`Uuid`] string.
532 /// [`Uuid`]: ../struct.Uuid.html
535 /// Creates a [`Simple`] from a [`Uuid`].
537 /// [`Uuid`]: ../struct.Uuid.html
539 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
540 Simple(uuid) in from_uuid()
543 /// Writes the [`Uuid`] as a lower-case simple string to `buffer`,
544 /// and returns the subslice of the buffer that contains the encoded UUID.
550 /// [`Uuid`]: ../struct.Uuid.html
555 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
559 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
564 /// use uuid::Uuid;
566 /// fn main() -> Result<(), uuid::Error> {
567 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
571 /// uuid.simple().encode_lower(&mut Uuid::encode_buffer()),
578 /// uuid.simple().encode_lower(&mut buf),
595 /// Writes the [`Uuid`] as an upper-case simple string to `buffer`,
596 /// and returns the subslice of the buffer that contains the encoded UUID.
598 /// [`Uuid`]: ../struct.Uuid.html
603 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
607 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
612 /// use uuid::Uuid;
614 /// fn main() -> Result<(), uuid::Error> {
615 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
619 /// uuid.simple().encode_upper(&mut Uuid::encode_buffer()),
626 /// uuid.simple().encode_upper(&mut buf),
643 /// Get a reference to the underlying [`Uuid`].
648 /// use uuid::Uuid;
650 /// let simple = Uuid::nil().simple();
651 /// assert_eq!(*simple.as_uuid(), Uuid::nil());
653 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
657 /// Consumes the [`Simple`], returning the underlying [`Uuid`].
662 /// use uuid::Uuid;
664 /// let simple = Uuid::nil().simple();
665 /// assert_eq!(simple.into_uuid(), Uuid::nil());
667 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
673 /// The length of a URN [`Uuid`] string.
675 /// [`Uuid`]: ../struct.Uuid.html
678 /// Creates a [`Urn`] from a [`Uuid`].
680 /// [`Uuid`]: ../struct.Uuid.html
682 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
683 Urn(uuid) in from_uuid()
686 /// Writes the [`Uuid`] as a lower-case URN string to
688 /// encoded UUID.
694 /// [`Uuid`]: ../struct.Uuid.html
699 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
703 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
708 /// use uuid::Uuid;
710 /// fn main() -> Result<(), uuid::Error> {
711 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
715 /// uuid.urn().encode_lower(&mut Uuid::encode_buffer()),
716 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
721 /// uuid.urn().encode_lower(&mut buf);
723 /// uuid.urn().encode_lower(&mut buf),
724 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
728 /// b"urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8!!!!" as &[_]
740 /// Writes the [`Uuid`] as an upper-case URN string to
742 /// encoded UUID.
748 /// [`Uuid`]: ../struct.Uuid.html
753 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
757 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
762 /// use uuid::Uuid;
764 /// fn main() -> Result<(), uuid::Error> {
765 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
769 /// uuid.urn().encode_upper(&mut Uuid::encode_buffer()),
770 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
776 /// uuid.urn().encode_upper(&mut buf),
777 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
781 /// b"urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8!!!!" as &[_]
793 /// Get a reference to the underlying [`Uuid`].
798 /// use uuid::Uuid;
800 /// let urn = Uuid::nil().urn();
801 /// assert_eq!(*urn.as_uuid(), Uuid::nil());
803 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
807 /// Consumes the [`Urn`], returning the underlying [`Uuid`].
812 /// use uuid::Uuid;
814 /// let urn = Uuid::nil().urn();
815 /// assert_eq!(urn.into_uuid(), Uuid::nil());
817 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
849 impl From<Uuid> for $T {
851 fn from(f: Uuid) -> Self {
856 impl From<$T> for Uuid {
863 impl AsRef<Uuid> for $T {
865 fn as_ref(&self) -> &Uuid {
870 impl Borrow<Uuid> for $T {
872 fn borrow(&self) -> &Uuid {
878 impl<$a> From<&$a Uuid> for $T<$a> {
880 fn from(f: &$a Uuid) -> Self {
885 impl<$a> From<$T<$a>> for &$a Uuid {
887 fn from(f: $T<$a>) -> &$a Uuid {
892 impl<$a> AsRef<Uuid> for $T<$a> {
894 fn as_ref(&self) -> &Uuid {
899 impl<$a> Borrow<Uuid> for $T<$a> {
901 fn borrow(&self) -> &Uuid {
922 let len = Uuid::nil().hyphenated().encode_lower(&mut buf).len(); in hyphenated_trailing()
930 let len = Uuid::nil().as_hyphenated().encode_lower(&mut buf).len(); in hyphenated_ref_trailing()
938 let len = Uuid::nil().simple().encode_lower(&mut buf).len(); in simple_trailing()
946 let len = Uuid::nil().as_simple().encode_lower(&mut buf).len(); in simple_ref_trailing()
954 let len = Uuid::nil().urn().encode_lower(&mut buf).len(); in urn_trailing()
962 let len = Uuid::nil().as_urn().encode_lower(&mut buf).len(); in urn_ref_trailing()
970 let len = Uuid::nil().braced().encode_lower(&mut buf).len(); in braced_trailing()
978 let len = Uuid::nil().as_braced().encode_lower(&mut buf).len(); in braced_ref_trailing()
986 Uuid::nil().hyphenated().encode_lower(&mut [0; 35]); in hyphenated_too_small()
992 Uuid::nil().simple().encode_lower(&mut [0; 31]); in simple_too_small()
998 Uuid::nil().urn().encode_lower(&mut [0; 44]); in urn_too_small()
1004 Uuid::nil().braced().encode_lower(&mut [0; 37]); in braced_too_small()
1009 let hyphenated = Uuid::nil().hyphenated(); in hyphenated_to_inner()
1010 assert_eq!(Uuid::from(hyphenated), Uuid::nil()); in hyphenated_to_inner()
1015 let simple = Uuid::nil().simple(); in simple_to_inner()
1016 assert_eq!(Uuid::from(simple), Uuid::nil()); in simple_to_inner()
1021 let urn = Uuid::nil().urn(); in urn_to_inner()
1022 assert_eq!(Uuid::from(urn), Uuid::nil()); in urn_to_inner()
1027 let braced = Uuid::nil().braced(); in braced_to_inner()
1028 assert_eq!(Uuid::from(braced), Uuid::nil()); in braced_to_inner()