Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added conversion for Vec<u8> #699

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/fmt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,27 @@

//! Adapters for alternative string formats.

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

impl From<Uuid> for Vec<u8>{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will need to be conditionally compiled, with a #[cfg(feature = “std”]).

fn from(value: Uuid) -> Self {
value.as_bytes().to_vec()
}
}

impl From<Vec<u8>> for Uuid{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should add this side of the conversion. Converting slices into Uuids is fallible, but we can't express that through this trait.

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]
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ mod macros;
#[doc(hidden)]
#[cfg(feature = "macro-diagnostics")]
pub extern crate uuid_macro_internal;
extern crate alloc;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also need to be conditionally compiled.


#[doc(hidden)]
pub mod __macro_support {
Expand Down