Skip to content

Commit

Permalink
Add PartialEq for more types
Browse files Browse the repository at this point in the history
  • Loading branch information
sunsided committed Apr 7, 2023
1 parent c871fe3 commit 839a93d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,13 @@ This project uses [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased

### Added

- Added `PartialEq<T>` for `Vec<u8>` 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

Expand Down
14 changes: 13 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -281,12 +281,24 @@ impl PartialEq<&str> for ShortGuid {
}
}

impl PartialEq<Vec<u8>> for ShortGuid {
fn eq(&self, other: &Vec<u8>) -> 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)
Expand Down

0 comments on commit 839a93d

Please sign in to comment.