diff options
author | 2020-10-16 15:45:38 -0700 | |
---|---|---|
committer | 2020-10-16 15:45:38 -0700 | |
commit | ced050730c7a5f9d322c0cf9aedea67f16151e90 (patch) | |
tree | 7b3ed1687879911b55c643cb7dc1a375c1b0bc66 /src/buf/buf_mut.rs | |
parent | 94c543f74b111e894d16faa43e4ad361b97ee87d (diff) | |
download | bytes-ced050730c7a5f9d322c0cf9aedea67f16151e90.tar.gz bytes-ced050730c7a5f9d322c0cf9aedea67f16151e90.tar.zst bytes-ced050730c7a5f9d322c0cf9aedea67f16151e90.zip |
Make BufMut an unsafe trait (#432)
Users of `BufMut` are unable to defend against incorrect implementations
of `BufMut`, this makes the trait unsafe to implement.
Fixes #329
Diffstat (limited to 'src/buf/buf_mut.rs')
-rw-r--r-- | src/buf/buf_mut.rs | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/buf/buf_mut.rs b/src/buf/buf_mut.rs index 4f6e47d..026bcad 100644 --- a/src/buf/buf_mut.rs +++ b/src/buf/buf_mut.rs @@ -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. /// @@ -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() @@ -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() |