Skip to content

Commit

Permalink
Add impl AsRef<[u8]> for Uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
hecsalazarf committed Jan 15, 2021
1 parent 3ae9926 commit 80d0a2c
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 80d0a2c

Please sign in to comment.