Skip to content

Commit 9ec593d

Browse files
authored
Implement Send and Sync for BoxBytes. (#299)
1 parent 1f6afb3 commit 9ec593d

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

src/allocation.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -783,6 +783,12 @@ pub struct BoxBytes {
783783
layout: Layout,
784784
}
785785

786+
// SAFETY: `BoxBytes` is semantically a `Box<[u8], Global>` with a different allocation alignment,
787+
// `Box<[u8], Global>` is `Send + Sync`, and changing the allocation alignment has no thread-safety implications.
788+
unsafe impl Send for BoxBytes {}
789+
// SAFETY: See `Send` impl
790+
unsafe impl Sync for BoxBytes {}
791+
786792
impl Deref for BoxBytes {
787793
type Target = [u8];
788794

0 commit comments

Comments
 (0)