From bb409b369f2ef3248b4e4d8a09d12dac880301e8 Mon Sep 17 00:00:00 2001 From: A248 Date: Sun, 6 Feb 2022 16:09:04 -0500 Subject: [PATCH 1/2] Add Uuid::into_bytes(self) Fixes #580 --- src/lib.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index e350b520..09e2ca9e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -759,6 +759,25 @@ impl Uuid { &self.0 } + /// Consumes self and returns the underlying byte value of the UUID. + /// + /// # Examples + /// + /// ``` + /// # use uuid::Uuid; + /// let bytes = [ + /// 0xa1, 0xa2, 0xa3, 0xa4, + /// 0xb1, 0xb2, + /// 0xc1, 0xc2, + /// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, + /// ]; + /// let uuid = Uuid::from_bytes(bytes.clone()); + /// assert_eq!(bytes, uuid.into_bytes()); + /// ``` + pub const fn into_bytes(self) -> Bytes { + self.0 + } + /// Tests if the UUID is nil. pub const fn is_nil(&self) -> bool { self.as_u128() == 0 From c41c6ceac9698a6f7fbe1bb6a89fb001cbfe504d Mon Sep 17 00:00:00 2001 From: A248 Date: Thu, 10 Feb 2022 17:24:00 -0500 Subject: [PATCH 2/2] Apply suggestion: remove .clone() from example --- src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 09e2ca9e..c9bb731e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -771,7 +771,7 @@ impl Uuid { /// 0xc1, 0xc2, /// 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, /// ]; - /// let uuid = Uuid::from_bytes(bytes.clone()); + /// let uuid = Uuid::from_bytes(bytes); /// assert_eq!(bytes, uuid.into_bytes()); /// ``` pub const fn into_bytes(self) -> Bytes {