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 ref-cast for BlobRef cast #641

Closed
skyzh opened this issue Apr 26, 2022 · 2 comments · Fixed by #643
Closed

use ref-cast for BlobRef cast #641

skyzh opened this issue Apr 26, 2022 · 2 comments · Fixed by #643
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@skyzh
Copy link
Member

skyzh commented Apr 26, 2022

https://github.com/dtolnay/ref-cast

Currently, we directly transmute these two types. We can use ref-cast crate to make it looks safer.

impl BlobRef {
pub fn new(bytes: &[u8]) -> &Self {
// SAFETY: `&BlobRef` and `&[u8]` have the same layout.
unsafe { std::mem::transmute(bytes) }
}
}

@skyzh skyzh added good first issue Good for newcomers enhancement New feature or request labels Apr 28, 2022
@Kikkon
Copy link
Contributor

Kikkon commented Apr 28, 2022

can I have a try?

@skyzh
Copy link
Member Author

skyzh commented Apr 28, 2022

Thanks! Please have a try.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants