Skip to content

Commit

Permalink
Merge #510
Browse files Browse the repository at this point in the history
510: Add impl AsRef<[u8]> for Uuid r=kinggoesgaming a=hecsalazarf

**I'm submitting a** feature.

# Description
Implement `AsRef<[u8]>` for `UUID`.

# Motivation
Open issue #472

# Tests
All existing tests pass.

# Related Issue(s)
closes #472

Co-authored-by: Hector Salazar <hecsalazarf@outlook.com>
  • Loading branch information
bors[bot] and hecsalazarf committed Jan 15, 2021
2 parents 3ae9926 + 80d0a2c commit c4238b0
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/lib.rs
Expand Up @@ -605,6 +605,13 @@ impl Default for Uuid {
}
}

impl AsRef<[u8]> for Uuid {
#[inline]
fn as_ref(&self) -> &[u8] {
&self.0
}
}

#[cfg(test)]
mod tests {
use crate::{
Expand Down Expand Up @@ -1038,9 +1045,12 @@ mod tests {
fn test_as_bytes() {
let u = test_util::new();
let ub = u.as_bytes();
let ur = u.as_ref();

assert_eq!(ub.len(), 16);
assert_eq!(ur.len(), 16);
assert!(!ub.iter().all(|&b| b == 0));
assert!(!ur.iter().all(|&b| b == 0));
}

#[test]
Expand Down

0 comments on commit c4238b0

Please sign in to comment.