• Home
  • Raw
  • Download

Lines Matching full:uuid

2 // Copyright 2018 The Uuid Project Developers.
16 Uuid, Variant,
22 impl std::fmt::Debug for Uuid { implementation
29 impl fmt::Display for Uuid { implementation
36 impl From<Uuid> for String {
37 fn from(uuid: Uuid) -> Self { in from()
38 uuid.to_string() in from()
53 impl fmt::LowerHex for Uuid { implementation
59 impl fmt::UpperHex for Uuid { implementation
66 /// Format a [`Uuid`] as a hyphenated string, like
70 pub struct Hyphenated(Uuid);
72 /// Format a [`Uuid`] as a simple string, like
76 pub struct Simple(Uuid);
78 /// Format a [`Uuid`] as a URN string, like
79 /// `urn:uuid:67e55044-10b1-426f-9247-bb680e5fe0c8`.
82 pub struct Urn(Uuid);
84 /// Format a [`Uuid`] as a braced hyphenated string, like
88 pub struct Braced(Uuid);
90 impl Uuid { impl
100 // SAFETY: `Uuid` and `Hyphenated` have the same ABI in as_hyphenated()
101 unsafe { &*(self as *const Uuid as *const Hyphenated) } in as_hyphenated() constant
113 // SAFETY: `Uuid` and `Simple` have the same ABI in as_simple()
114 unsafe { &*(self as *const Uuid as *const Simple) } in as_simple() constant
126 // SAFETY: `Uuid` and `Urn` have the same ABI in as_urn()
127 unsafe { &*(self as *const Uuid as *const Urn) } in as_urn() constant
139 // SAFETY: `Uuid` and `Braced` have the same ABI in as_braced()
140 unsafe { &*(self as *const Uuid as *const Braced) } in as_braced() constant
237 buf[..9].copy_from_slice(b"urn:uuid:");
250 /// The length of a hyphenated [`Uuid`] string.
252 /// [`Uuid`]: ../struct.Uuid.html
255 /// Creates a [`Hyphenated`] from a [`Uuid`].
257 /// [`Uuid`]: ../struct.Uuid.html
259 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
260 Hyphenated(uuid) in from_uuid()
263 /// Writes the [`Uuid`] as a lower-case hyphenated string to
265 /// encoded UUID.
271 /// [`Uuid`]: ../struct.Uuid.html
276 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
280 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
285 /// use uuid::Uuid;
287 /// fn main() -> Result<(), uuid::Error> {
288 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
292 /// uuid.hyphenated()
293 /// .encode_lower(&mut Uuid::encode_buffer()),
299 /// uuid.hyphenated().encode_lower(&mut buf);
314 /// Writes the [`Uuid`] as an upper-case hyphenated string to
316 /// encoded UUID.
322 /// [`Uuid`]: ../struct.Uuid.html
327 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
331 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
336 /// use uuid::Uuid;
338 /// fn main() -> Result<(), uuid::Error> {
339 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
343 /// uuid.hyphenated()
344 /// .encode_upper(&mut Uuid::encode_buffer()),
350 /// uuid.hyphenated().encode_upper(&mut buf);
365 /// Get a reference to the underlying [`Uuid`].
370 /// use uuid::Uuid;
372 /// let hyphenated = Uuid::nil().hyphenated();
373 /// assert_eq!(*hyphenated.as_uuid(), Uuid::nil());
375 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
379 /// Consumes the [`Hyphenated`], returning the underlying [`Uuid`].
384 /// use uuid::Uuid;
386 /// let hyphenated = Uuid::nil().hyphenated();
387 /// assert_eq!(hyphenated.into_uuid(), Uuid::nil());
389 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
395 /// The length of a braced [`Uuid`] string.
397 /// [`Uuid`]: ../struct.Uuid.html
400 /// Creates a [`Braced`] from a [`Uuid`].
402 /// [`Uuid`]: ../struct.Uuid.html
404 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
405 Braced(uuid) in from_uuid()
408 /// Writes the [`Uuid`] as a lower-case hyphenated string surrounded by
410 /// the encoded UUID.
416 /// [`Uuid`]: ../struct.Uuid.html
421 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
425 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
430 /// use uuid::Uuid;
432 /// fn main() -> Result<(), uuid::Error> {
433 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
437 /// uuid.braced()
438 /// .encode_lower(&mut Uuid::encode_buffer()),
444 /// uuid.braced().encode_lower(&mut buf);
459 /// Writes the [`Uuid`] as an upper-case hyphenated string surrounded by
461 /// the encoded UUID.
467 /// [`Uuid`]: ../struct.Uuid.html
472 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
476 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
481 /// use uuid::Uuid;
483 /// fn main() -> Result<(), uuid::Error> {
484 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
488 /// uuid.braced()
489 /// .encode_upper(&mut Uuid::encode_buffer()),
495 /// uuid.braced().encode_upper(&mut buf);
510 /// Get a reference to the underlying [`Uuid`].
515 /// use uuid::Uuid;
517 /// let braced = Uuid::nil().braced();
518 /// assert_eq!(*braced.as_uuid(), Uuid::nil());
520 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
524 /// Consumes the [`Braced`], returning the underlying [`Uuid`].
529 /// use uuid::Uuid;
531 /// let braced = Uuid::nil().braced();
532 /// assert_eq!(braced.into_uuid(), Uuid::nil());
534 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
540 /// The length of a simple [`Uuid`] string.
542 /// [`Uuid`]: ../struct.Uuid.html
545 /// Creates a [`Simple`] from a [`Uuid`].
547 /// [`Uuid`]: ../struct.Uuid.html
549 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
550 Simple(uuid) in from_uuid()
553 /// Writes the [`Uuid`] as a lower-case simple string to `buffer`,
554 /// and returns the subslice of the buffer that contains the encoded UUID.
560 /// [`Uuid`]: ../struct.Uuid.html
565 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
569 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
574 /// use uuid::Uuid;
576 /// fn main() -> Result<(), uuid::Error> {
577 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
581 /// uuid.simple().encode_lower(&mut Uuid::encode_buffer()),
588 /// uuid.simple().encode_lower(&mut buf),
605 /// Writes the [`Uuid`] as an upper-case simple string to `buffer`,
606 /// and returns the subslice of the buffer that contains the encoded UUID.
608 /// [`Uuid`]: ../struct.Uuid.html
613 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
617 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
622 /// use uuid::Uuid;
624 /// fn main() -> Result<(), uuid::Error> {
625 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
629 /// uuid.simple().encode_upper(&mut Uuid::encode_buffer()),
636 /// uuid.simple().encode_upper(&mut buf),
653 /// Get a reference to the underlying [`Uuid`].
658 /// use uuid::Uuid;
660 /// let simple = Uuid::nil().simple();
661 /// assert_eq!(*simple.as_uuid(), Uuid::nil());
663 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
667 /// Consumes the [`Simple`], returning the underlying [`Uuid`].
672 /// use uuid::Uuid;
674 /// let simple = Uuid::nil().simple();
675 /// assert_eq!(simple.into_uuid(), Uuid::nil());
677 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
683 /// The length of a URN [`Uuid`] string.
685 /// [`Uuid`]: ../struct.Uuid.html
688 /// Creates a [`Urn`] from a [`Uuid`].
690 /// [`Uuid`]: ../struct.Uuid.html
692 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
693 Urn(uuid) in from_uuid()
696 /// Writes the [`Uuid`] as a lower-case URN string to
698 /// encoded UUID.
704 /// [`Uuid`]: ../struct.Uuid.html
709 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
713 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
718 /// use uuid::Uuid;
720 /// fn main() -> Result<(), uuid::Error> {
721 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
725 /// uuid.urn().encode_lower(&mut Uuid::encode_buffer()),
726 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
731 /// uuid.urn().encode_lower(&mut buf);
733 /// uuid.urn().encode_lower(&mut buf),
734 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
738 /// b"urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8!!!!" as &[_]
750 /// Writes the [`Uuid`] as an upper-case URN string to
752 /// encoded UUID.
758 /// [`Uuid`]: ../struct.Uuid.html
763 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
767 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
772 /// use uuid::Uuid;
774 /// fn main() -> Result<(), uuid::Error> {
775 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
779 /// uuid.urn().encode_upper(&mut Uuid::encode_buffer()),
780 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
786 /// uuid.urn().encode_upper(&mut buf),
787 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
791 /// b"urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8!!!!" as &[_]
803 /// Get a reference to the underlying [`Uuid`].
808 /// use uuid::Uuid;
810 /// let urn = Uuid::nil().urn();
811 /// assert_eq!(*urn.as_uuid(), Uuid::nil());
813 pub const fn as_uuid(&self) -> &Uuid { in as_uuid() argument
817 /// Consumes the [`Urn`], returning the underlying [`Uuid`].
822 /// use uuid::Uuid;
824 /// let urn = Uuid::nil().urn();
825 /// assert_eq!(urn.into_uuid(), Uuid::nil());
827 pub const fn into_uuid(self) -> Uuid { in into_uuid() argument
859 impl From<Uuid> for $T {
861 fn from(f: Uuid) -> Self {
866 impl From<$T> for Uuid {
873 impl AsRef<Uuid> for $T {
875 fn as_ref(&self) -> &Uuid {
880 impl Borrow<Uuid> for $T {
882 fn borrow(&self) -> &Uuid {
888 impl<$a> From<&$a Uuid> for $T<$a> {
890 fn from(f: &$a Uuid) -> Self {
895 impl<$a> From<$T<$a>> for &$a Uuid {
897 fn from(f: $T<$a>) -> &$a Uuid {
902 impl<$a> AsRef<Uuid> for $T<$a> {
904 fn as_ref(&self) -> &Uuid {
909 impl<$a> Borrow<Uuid> for $T<$a> {
911 fn borrow(&self) -> &Uuid {
932 let len = Uuid::nil().hyphenated().encode_lower(&mut buf).len(); in hyphenated_trailing()
940 let len = Uuid::nil().as_hyphenated().encode_lower(&mut buf).len(); in hyphenated_ref_trailing()
948 let len = Uuid::nil().simple().encode_lower(&mut buf).len(); in simple_trailing()
956 let len = Uuid::nil().as_simple().encode_lower(&mut buf).len(); in simple_ref_trailing()
964 let len = Uuid::nil().urn().encode_lower(&mut buf).len(); in urn_trailing()
972 let len = Uuid::nil().as_urn().encode_lower(&mut buf).len(); in urn_ref_trailing()
980 let len = Uuid::nil().braced().encode_lower(&mut buf).len(); in braced_trailing()
988 let len = Uuid::nil().as_braced().encode_lower(&mut buf).len(); in braced_ref_trailing()
996 Uuid::nil().hyphenated().encode_lower(&mut [0; 35]); in hyphenated_too_small()
1002 Uuid::nil().simple().encode_lower(&mut [0; 31]); in simple_too_small()
1008 Uuid::nil().urn().encode_lower(&mut [0; 44]); in urn_too_small()
1014 Uuid::nil().braced().encode_lower(&mut [0; 37]); in braced_too_small()
1019 let hyphenated = Uuid::nil().hyphenated(); in hyphenated_to_inner()
1020 assert_eq!(Uuid::from(hyphenated), Uuid::nil()); in hyphenated_to_inner()
1025 let simple = Uuid::nil().simple(); in simple_to_inner()
1026 assert_eq!(Uuid::from(simple), Uuid::nil()); in simple_to_inner()
1031 let urn = Uuid::nil().urn(); in urn_to_inner()
1032 assert_eq!(Uuid::from(urn), Uuid::nil()); in urn_to_inner()
1037 let braced = Uuid::nil().braced(); in braced_to_inner()
1038 assert_eq!(Uuid::from(braced), Uuid::nil()); in braced_to_inner()