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

Replace unsafe with safe code :) #358

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
11 changes: 3 additions & 8 deletions rmp/src/encode/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,9 @@ impl<'a> RmpWrite for &'a mut [u8] {
let to_write = buf.len();
let remaining = self.len();
if to_write <= remaining {
self[..to_write].copy_from_slice(buf);
unsafe {
//Cant use split_at or re-borrowing due to lifetime errors :(
*self = core::slice::from_raw_parts_mut(
self.as_mut_ptr().add(to_write),
remaining - to_write,
)
}
let (a, b) = core::mem::take(self).split_at_mut(to_write);
a.copy_from_slice(buf);
*self = b;
Ok(())
} else {
Err(FixedBufCapacityOverflow { _priv: () })
Expand Down