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

Make BufMut an unsafe trait #432

Merged
merged 1 commit into from Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/buf/buf_mut.rs
Expand Up @@ -30,7 +30,7 @@ use alloc::{boxed::Box, vec::Vec};
///
/// assert_eq!(buf, b"hello world");
/// ```
pub trait BufMut {
pub unsafe trait BufMut {
/// Returns the number of bytes that can be written from the current
/// position until the end of the buffer is reached.
///
Expand Down Expand Up @@ -992,15 +992,15 @@ macro_rules! deref_forward_bufmut {
};
}

impl<T: BufMut + ?Sized> BufMut for &mut T {
unsafe impl<T: BufMut + ?Sized> BufMut for &mut T {
deref_forward_bufmut!();
}

impl<T: BufMut + ?Sized> BufMut for Box<T> {
unsafe impl<T: BufMut + ?Sized> BufMut for Box<T> {
deref_forward_bufmut!();
}

impl BufMut for &mut [u8] {
unsafe impl BufMut for &mut [u8] {
#[inline]
fn remaining_mut(&self) -> usize {
self.len()
Expand All @@ -1020,7 +1020,7 @@ impl BufMut for &mut [u8] {
}
}

impl BufMut for Vec<u8> {
unsafe impl BufMut for Vec<u8> {
#[inline]
fn remaining_mut(&self) -> usize {
usize::MAX - self.len()
Expand Down
2 changes: 1 addition & 1 deletion src/buf/chain.rs
Expand Up @@ -174,7 +174,7 @@ where
}
}

impl<T, U> BufMut for Chain<T, U>
unsafe impl<T, U> BufMut for Chain<T, U>
where
T: BufMut,
U: BufMut,
Expand Down
2 changes: 1 addition & 1 deletion src/buf/limit.rs
Expand Up @@ -55,7 +55,7 @@ impl<T> Limit<T> {
}
}

impl<T: BufMut> BufMut for Limit<T> {
unsafe impl<T: BufMut> BufMut for Limit<T> {
fn remaining_mut(&self) -> usize {
cmp::min(self.inner.remaining_mut(), self.limit)
}
Expand Down
2 changes: 1 addition & 1 deletion src/bytes_mut.rs
Expand Up @@ -966,7 +966,7 @@ impl Buf for BytesMut {
}
}

impl BufMut for BytesMut {
unsafe impl BufMut for BytesMut {
#[inline]
fn remaining_mut(&self) -> usize {
usize::MAX - self.len()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_buf_mut.rs
Expand Up @@ -75,7 +75,7 @@ fn test_mut_slice() {
fn test_deref_bufmut_forwards() {
struct Special;

impl BufMut for Special {
unsafe impl BufMut for Special {
fn remaining_mut(&self) -> usize {
unreachable!("remaining_mut");
}
Expand Down