Lines Matching full:uuid
2 // Copyright 2018 The Uuid Project Developers.
20 /// An adaptor for formatting an [`Uuid`] as a hyphenated string.
22 /// Takes an owned instance of the [`Uuid`].
24 /// [`Uuid`]: ../struct.Uuid.html
26 pub struct Hyphenated(Uuid);
28 /// An adaptor for formatting an [`Uuid`] as a hyphenated string.
30 /// Takes a reference of the [`Uuid`].
32 /// [`Uuid`]: ../struct.Uuid.html
34 pub struct HyphenatedRef<'a>(&'a Uuid);
36 /// An adaptor for formatting an [`Uuid`] as a simple string.
38 /// Takes an owned instance of the [`Uuid`].
40 /// [`Uuid`]: ../struct.Uuid.html
42 pub struct Simple(Uuid);
44 /// An adaptor for formatting an [`Uuid`] as a simple string.
46 /// Takes a reference of the [`Uuid`].
48 /// [`Uuid`]: ../struct.Uuid.html
50 pub struct SimpleRef<'a>(&'a Uuid);
52 /// An adaptor for formatting an [`Uuid`] as a URN string.
54 /// Takes an owned instance of the [`Uuid`].
56 /// [`Uuid`]: ../struct.Uuid.html
58 pub struct Urn(Uuid);
60 /// An adaptor for formatting an [`Uuid`] as a URN string.
62 /// Takes a reference of the [`Uuid`].
64 /// [`Uuid`]: ../struct.Uuid.html
66 pub struct UrnRef<'a>(&'a Uuid);
68 impl Uuid { impl
103 /// [`Uuid`]: ../struct.Uuid.html
112 /// [`Uuid`]: ../struct.Uuid.html
128 /// The segments of a UUID's [u8; 16] corresponding to each group.
134 /// Encodes the `uuid` possibly with hyphens, and possibly in upper
139 /// "urn:uuid:") to the buffer that's included in the final encoded
140 /// UUID.
145 uuid: &Uuid, in encode() argument
153 let bytes = uuid.as_bytes(); in encode()
178 .expect("found non-ASCII output characters while encoding a UUID") in encode()
182 /// The length of a hyphenated [`Uuid`] string.
184 /// [`Uuid`]: ../struct.Uuid.html
187 /// Creates a [`Hyphenated`] from a [`Uuid`].
189 /// [`Uuid`]: ../struct.Uuid.html
191 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
192 Hyphenated(uuid) in from_uuid()
195 /// Writes the [`Uuid`] as a lower-case hyphenated string to
197 /// encoded UUID.
203 /// [`Uuid`]: ../struct.Uuid.html
208 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
212 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
217 /// use uuid::Uuid;
219 /// fn main() -> Result<(), uuid::Error> {
220 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
224 /// uuid.to_hyphenated()
225 /// .encode_lower(&mut Uuid::encode_buffer()),
231 /// uuid.to_hyphenated().encode_lower(&mut buf);
245 /// Writes the [`Uuid`] as an upper-case hyphenated string to
247 /// encoded UUID.
253 /// [`Uuid`]: ../struct.Uuid.html
258 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
262 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
267 /// use uuid::Uuid;
269 /// fn main() -> Result<(), uuid::Error> {
270 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
274 /// uuid.to_hyphenated()
275 /// .encode_upper(&mut Uuid::encode_buffer()),
281 /// uuid.to_hyphenated().encode_upper(&mut buf);
297 /// The length of a hyphenated [`Uuid`] string.
299 /// [`Uuid`]: ../struct.Uuid.html
302 /// Creates a [`HyphenatedRef`] from a [`Uuid`] reference.
304 /// [`Uuid`]: ../struct.Uuid.html
306 pub const fn from_uuid_ref(uuid: &'a Uuid) -> Self { in from_uuid_ref()
307 HyphenatedRef(uuid) in from_uuid_ref()
310 /// Writes the [`Uuid`] as a lower-case hyphenated string to
312 /// encoded UUID.
318 /// [`Uuid`]: ../struct.Uuid.html
323 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
327 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
332 /// use uuid::Uuid;
334 /// fn main() -> Result<(), uuid::Error> {
335 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
339 /// uuid.to_hyphenated()
340 /// .encode_lower(&mut Uuid::encode_buffer()),
346 /// uuid.to_hyphenated().encode_lower(&mut buf);
348 /// uuid.to_hyphenated().encode_lower(&mut buf),
364 /// Writes the [`Uuid`] as an upper-case hyphenated string to
366 /// encoded UUID.
372 /// [`Uuid`]: ../struct.Uuid.html
377 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
381 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
386 /// use uuid::Uuid;
388 /// fn main() -> Result<(), uuid::Error> {
389 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
393 /// uuid.to_hyphenated()
394 /// .encode_upper(&mut Uuid::encode_buffer()),
401 /// uuid.to_hyphenated().encode_upper(&mut buf),
419 /// The length of a simple [`Uuid`] string.
421 /// [`Uuid`]: ../struct.Uuid.html
424 /// Creates a [`Simple`] from a [`Uuid`].
426 /// [`Uuid`]: ../struct.Uuid.html
428 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
429 Simple(uuid) in from_uuid()
432 /// Writes the [`Uuid`] as a lower-case simple string to `buffer`,
433 /// and returns the subslice of the buffer that contains the encoded UUID.
439 /// [`Uuid`]: ../struct.Uuid.html
444 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
448 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
453 /// use uuid::Uuid;
455 /// fn main() -> Result<(), uuid::Error> {
456 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
460 /// uuid.to_simple().encode_lower(&mut Uuid::encode_buffer()),
467 /// uuid.to_simple().encode_lower(&mut buf),
483 /// Writes the [`Uuid`] as an upper-case simple string to `buffer`,
484 /// and returns the subslice of the buffer that contains the encoded UUID.
486 /// [`Uuid`]: ../struct.Uuid.html
491 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
495 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
500 /// use uuid::Uuid;
502 /// fn main() -> Result<(), uuid::Error> {
503 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
507 /// uuid.to_simple().encode_upper(&mut Uuid::encode_buffer()),
514 /// uuid.to_simple().encode_upper(&mut buf),
532 /// The length of a simple [`Uuid`] string.
534 /// [`Uuid`]: ../struct.Uuid.html
537 /// Creates a [`SimpleRef`] from a [`Uuid`] reference.
539 /// [`Uuid`]: ../struct.Uuid.html
541 pub const fn from_uuid_ref(uuid: &'a Uuid) -> Self { in from_uuid_ref()
542 SimpleRef(uuid) in from_uuid_ref()
545 /// Writes the [`Uuid`] as a lower-case simple string to `buffer`,
546 /// and returns the subslice of the buffer that contains the encoded UUID.
552 /// [`Uuid`]: ../struct.Uuid.html
557 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
561 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
566 /// use uuid::Uuid;
568 /// fn main() -> Result<(), uuid::Error> {
569 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
573 /// uuid.to_simple().encode_lower(&mut Uuid::encode_buffer()),
580 /// uuid.to_simple().encode_lower(&mut buf),
596 /// Writes the [`Uuid`] as an upper-case simple string to `buffer`,
597 /// and returns the subslice of the buffer that contains the encoded UUID.
599 /// [`Uuid`]: ../struct.Uuid.html
604 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
608 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
613 /// use uuid::Uuid;
615 /// fn main() -> Result<(), uuid::Error> {
616 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
620 /// uuid.to_simple().encode_upper(&mut Uuid::encode_buffer()),
627 /// uuid.to_simple().encode_upper(&mut buf),
645 /// The length of a URN [`Uuid`] string.
647 /// [`Uuid`]: ../struct.Uuid.html
650 /// Creates a [`Urn`] from a [`Uuid`].
652 /// [`Uuid`]: ../struct.Uuid.html
654 pub const fn from_uuid(uuid: Uuid) -> Self { in from_uuid()
655 Urn(uuid) in from_uuid()
658 /// Writes the [`Uuid`] as a lower-case URN string to
660 /// encoded UUID.
666 /// [`Uuid`]: ../struct.Uuid.html
671 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
675 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
680 /// use uuid::Uuid;
682 /// fn main() -> Result<(), uuid::Error> {
683 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
687 /// uuid.to_urn().encode_lower(&mut Uuid::encode_buffer()),
688 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
693 /// uuid.to_urn().encode_lower(&mut buf);
695 /// uuid.to_urn().encode_lower(&mut buf),
696 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
700 /// b"urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8!!!!" as &[_]
708 buffer[..9].copy_from_slice(b"urn:uuid:"); in encode_lower()
712 /// Writes the [`Uuid`] as an upper-case URN string to
714 /// encoded UUID.
720 /// [`Uuid`]: ../struct.Uuid.html
725 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
729 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
734 /// use uuid::Uuid;
736 /// fn main() -> Result<(), uuid::Error> {
737 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
741 /// uuid.to_urn().encode_upper(&mut Uuid::encode_buffer()),
742 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
748 /// uuid.to_urn().encode_upper(&mut buf),
749 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
753 /// b"urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8!!!!" as &[_]
761 buffer[..9].copy_from_slice(b"urn:uuid:"); in encode_upper()
767 /// The length of a URN [`Uuid`] string.
769 /// [`Uuid`]: ../struct.Uuid.html
772 /// Creates a [`UrnRef`] from a [`Uuid`] reference.
774 /// [`Uuid`]: ../struct.Uuid.html
776 pub const fn from_uuid_ref(uuid: &'a Uuid) -> Self { in from_uuid_ref()
777 UrnRef(&uuid) in from_uuid_ref()
780 /// Writes the [`Uuid`] as a lower-case URN string to
782 /// encoded UUID.
788 /// [`Uuid`]: ../struct.Uuid.html
793 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
797 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
802 /// use uuid::Uuid;
804 /// fn main() -> Result<(), uuid::Error> {
805 /// let uuid = Uuid::parse_str("936DA01f9abd4d9d80c702af85c822a8")?;
809 /// uuid.to_urn().encode_lower(&mut Uuid::encode_buffer()),
810 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
815 /// uuid.to_urn().encode_lower(&mut buf);
817 /// uuid.to_urn().encode_lower(&mut buf),
818 /// "urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8"
822 /// b"urn:uuid:936da01f-9abd-4d9d-80c7-02af85c822a8!!!!" as &[_]
830 buffer[..9].copy_from_slice(b"urn:uuid:"); in encode_lower()
834 /// Writes the [`Uuid`] as an upper-case URN string to
836 /// encoded UUID.
842 /// [`Uuid`]: ../struct.Uuid.html
847 /// [`LENGTH`]. [`Uuid::encode_buffer`] can be used to get a
851 /// [`Uuid::encode_buffer`]: ../struct.Uuid.html#method.encode_buffer
856 /// use uuid::Uuid;
858 /// fn main() -> Result<(), uuid::Error> {
859 /// let uuid = Uuid::parse_str("936da01f9abd4d9d80c702af85c822a8")?;
863 /// uuid.to_urn().encode_upper(&mut Uuid::encode_buffer()),
864 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
870 /// uuid.to_urn().encode_upper(&mut buf),
871 /// "urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8"
875 /// b"urn:uuid:936DA01F-9ABD-4D9D-80C7-02AF85C822A8!!!!" as &[_]
883 buffer[..9].copy_from_slice(b"urn:uuid:"); in encode_upper()
917 impl From<Uuid> for $T {
919 fn from(f: Uuid) -> Self {
925 impl<$a> From<&$a Uuid> for $T<$a> {
927 fn from(f: &$a Uuid) -> Self {
950 let len = Uuid::nil().to_hyphenated().encode_lower(&mut buf).len(); in hyphenated_trailing()
958 let len = Uuid::nil().to_hyphenated().encode_lower(&mut buf).len(); in hyphenated_ref_trailing()
966 let len = Uuid::nil().to_simple().encode_lower(&mut buf).len(); in simple_trailing()
974 let len = Uuid::nil().to_simple().encode_lower(&mut buf).len(); in simple_ref_trailing()
982 let len = Uuid::nil().to_urn().encode_lower(&mut buf).len(); in urn_trailing()
990 let len = Uuid::nil().to_urn().encode_lower(&mut buf).len(); in urn_ref_trailing()
998 Uuid::nil().to_hyphenated().encode_lower(&mut [0; 35]); in hyphenated_too_small()
1004 Uuid::nil().to_hyphenated_ref().encode_lower(&mut [0; 35]); in hyphenated_ref_too_small()
1010 Uuid::nil().to_simple().encode_lower(&mut [0; 31]); in simple_too_small()
1015 Uuid::nil().to_simple_ref().encode_lower(&mut [0; 31]); in simple_ref_too_small()
1020 Uuid::nil().to_urn().encode_lower(&mut [0; 44]); in urn_too_small()
1025 Uuid::nil().to_urn_ref().encode_lower(&mut [0; 44]); in urn_ref_too_small()