From 839a93da8791bed94b2225b5224cf592202e5815 Mon Sep 17 00:00:00 2001 From: Markus Mayer Date: Sat, 8 Apr 2023 01:33:20 +0200 Subject: [PATCH] Add PartialEq for more types --- CHANGELOG.md | 6 +++++- src/lib.rs | 14 +++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index edcbb99..efe3fa7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,9 +5,13 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## Unreleased +### Added + +- Added `PartialEq` for `Vec` and `&[u8; 16]`. + ### Changed -- `from_bytes_ref`, `as_uuid` and `is_empty` are now `const`. +- `to_bytes_le`, `from_bytes_ref`, `as_uuid` and `is_empty` are now `const`. ### Internal diff --git a/src/lib.rs b/src/lib.rs index 96f2f77..fd9053a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -153,7 +153,7 @@ impl ShortGuid { /// # } /// ``` #[inline] - pub fn to_bytes_le(&self) -> [u8; 16] { + pub const fn to_bytes_le(&self) -> [u8; 16] { self.0.to_bytes_le() } @@ -281,12 +281,24 @@ impl PartialEq<&str> for ShortGuid { } } +impl PartialEq> for ShortGuid { + fn eq(&self, other: &Vec) -> bool { + other.len() == 16 && self.as_bytes().eq(other.as_slice()) + } +} + impl PartialEq<&[u8]> for ShortGuid { fn eq(&self, other: &&[u8]) -> bool { other.len() == 16 && self.as_bytes().eq(other) } } +impl PartialEq<&[u8; 16]> for ShortGuid { + fn eq(&self, other: &&[u8; 16]) -> bool { + self.as_bytes().eq(*other) + } +} + impl PartialEq<[u8; 16]> for ShortGuid { fn eq(&self, other: &[u8; 16]) -> bool { self.as_bytes().eq(other)