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

Use TryInto to avoid unsafe. #507

Merged
merged 2 commits into from
Jan 17, 2021
Merged
Changes from 1 commit
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
8 changes: 3 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ mod v5;
#[cfg(all(windows, feature = "winapi"))]
mod winapi_support;

use crate::std::{fmt, str};
use crate::std::{convert::TryInto, fmt, str};
kinggoesgaming marked this conversation as resolved.
Show resolved Hide resolved

pub use crate::error::Error;

Expand Down Expand Up @@ -390,8 +390,7 @@ impl Uuid {
let d3 =
u16::from(self.as_bytes()[6]) << 8 | u16::from(self.as_bytes()[7]);

let d4: &[u8; 8] =
unsafe { &*(self.as_bytes()[8..16].as_ptr() as *const [u8; 8]) };
let d4: &[u8; 8] = self.as_bytes()[8..16].try_into().unwrap();
(d1, d2, d3, d4)
}

Expand Down Expand Up @@ -431,8 +430,7 @@ impl Uuid {
let d3 =
u16::from(self.as_bytes()[6]) | u16::from(self.as_bytes()[7]) << 8;

let d4: &[u8; 8] =
unsafe { &*(self.as_bytes()[8..16].as_ptr() as *const [u8; 8]) };
let d4: &[u8; 8] = self.as_bytes()[8..16].try_into().unwrap();
(d1, d2, d3, d4)
}

Expand Down