Skip to content

Commit

Permalink
added from vec for uuid
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeremiah-Griffin committed Aug 6, 2023
1 parent ee1bbf2 commit 1a8e8d4
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,27 @@
//! Adapters for alternative string formats.

use alloc::vec::Vec;
use crate::{
std::{borrow::Borrow, fmt, ptr, str},
Uuid, Variant,
};
use crate::{Bytes, std::{borrow::Borrow, fmt, ptr, str}, Uuid, Variant};

impl From<Uuid> for Vec<u8>{
fn from(value: Uuid) -> Self {
value.as_bytes().to_vec()
}
}

impl From<Vec<u8>> for Uuid{
fn from(value: Vec<u8>) -> Self {
let mut arr: [u8; 16] = [0;16];

value.into_iter()
.take(16)
.enumerate()
.for_each(|(i, v)| arr[i] = v);

Uuid(arr)
}
}

impl std::fmt::Debug for Uuid {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down

0 comments on commit 1a8e8d4

Please sign in to comment.