mirror of
https://github.com/tokio-rs/bytes.git
synced 2026-08-16 00:00:15 +02:00
chore: add safety comments on unsafe blocks (#827)
This commit is contained in:
@@ -489,6 +489,8 @@ impl Bytes {
|
||||
|
||||
self.len = at;
|
||||
|
||||
// SAFETY: `at` has been asserted to be <= `self.len()`, and the
|
||||
// `at == self.len()` and `at == 0` cases were handled above.
|
||||
unsafe { ret.inc_start(at) };
|
||||
|
||||
ret
|
||||
@@ -537,6 +539,8 @@ impl Bytes {
|
||||
|
||||
let mut ret = self.clone();
|
||||
|
||||
// SAFETY: `at` has been asserted to be <= `self.len()`, and the
|
||||
// `at == self.len()` and `at == 0` cases were handled above.
|
||||
unsafe { self.inc_start(at) };
|
||||
|
||||
ret.len = at;
|
||||
|
||||
@@ -324,6 +324,10 @@ impl BytesMut {
|
||||
self.capacity(),
|
||||
);
|
||||
unsafe {
|
||||
// SAFETY: `shallow_clone` increments the reference count (or
|
||||
// promotes to shared) and returns a bitwise copy of the handle.
|
||||
// The caller immediately adjusts both handles so they represent
|
||||
// disjoint regions.
|
||||
let mut other = self.shallow_clone();
|
||||
// SAFETY: We've checked that `at` <= `self.capacity()` above.
|
||||
other.advance_unchecked(at);
|
||||
@@ -400,6 +404,10 @@ impl BytesMut {
|
||||
);
|
||||
|
||||
unsafe {
|
||||
// SAFETY: `shallow_clone` increments the reference count (or
|
||||
// promotes to shared) and returns a bitwise copy of the handle.
|
||||
// The caller immediately adjusts both handles so they represent
|
||||
// disjoint regions.
|
||||
let mut other = self.shallow_clone();
|
||||
// SAFETY: We've checked that `at` <= `self.len()` and we know that `self.len()` <=
|
||||
// `self.capacity()`.
|
||||
|
||||
Reference in New Issue
Block a user