Skip to content

Commit 8736d17

Browse files
committed
Mostly revert previous commit. I think it's not needed
1 parent 26676dd commit 8736d17

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

capnp/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl <'a> ::std::ops::Deref for OutputSegments<'a> {
258258
}
259259
}
260260

261-
unsafe impl<'s> message::ReaderSegments for OutputSegments<'s> {
261+
impl<'s> message::ReaderSegments for OutputSegments<'s> {
262262
fn get_segment<'a>(&'a self, id: u32) -> Option<&'a [u8]> {
263263
match *self {
264264
OutputSegments::SingleSegment(ref s) => {

capnp/src/message.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,15 @@ impl ReaderOptions {
8787
}
8888

8989
/// An object that manages the buffers underlying a Cap'n Proto message reader.
90-
pub unsafe trait ReaderSegments {
90+
pub trait ReaderSegments {
9191
/// Gets the segment with index `idx`. Returns `None` if `idx` is out of range.
9292
///
9393
/// The segment must be 8-byte aligned or the "unaligned" feature must
9494
/// be enabled in the capnp crate. (Otherwise reading the segment will return an error.)
9595
///
96-
/// UNSAFETY ALERT: implementors must ensure that the returned slice points to memory that remains
97-
/// valid until the ReaderSegments object is dropped.
96+
/// The returned slice is required to point to memory that remains valid until the ReaderSegments
97+
/// object is dropped. In safe Rust, it should not be possible to violate this requirement. (If we
98+
/// discover that it is possible, then we need to mark this trait as `unsafe`.)
9899
fn get_segment<'a>(&'a self, idx: u32) -> Option<&'a [u8]>;
99100

100101
/// Gets the number of segments.
@@ -119,7 +120,7 @@ impl <'a> SegmentArray<'a> {
119120
}
120121
}
121122

122-
unsafe impl <'b> ReaderSegments for SegmentArray<'b> {
123+
impl <'b> ReaderSegments for SegmentArray<'b> {
123124
fn get_segment<'a>(&'a self, id: u32) -> Option<&'a [u8]> {
124125
self.segments.get(id as usize).map(|slice| *slice)
125126
}
@@ -129,7 +130,7 @@ unsafe impl <'b> ReaderSegments for SegmentArray<'b> {
129130
}
130131
}
131132

132-
unsafe impl <'b> ReaderSegments for [&'b [u8]] {
133+
impl <'b> ReaderSegments for [&'b [u8]] {
133134
fn get_segment<'a>(&'a self, id: u32) -> Option<&'a [u8]> {
134135
self.get(id as usize).map(|slice| *slice)
135136
}
@@ -382,7 +383,7 @@ impl <A> Builder<A> where A: Allocator {
382383
}
383384
}
384385

385-
unsafe impl <A> ReaderSegments for Builder<A> where A: Allocator {
386+
impl <A> ReaderSegments for Builder<A> where A: Allocator {
386387
fn get_segment<'a>(&'a self, id: u32) -> Option<&'a [u8]> {
387388
self.get_segments_for_output().get(id as usize).map(|x| *x)
388389
}

capnp/src/serialize.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub struct SliceSegments<'a> {
3939
segment_indices : Vec<(usize, usize)>,
4040
}
4141

42-
unsafe impl <'a> message::ReaderSegments for SliceSegments<'a> {
42+
impl <'a> message::ReaderSegments for SliceSegments<'a> {
4343
fn get_segment<'b>(&'b self, id: u32) -> Option<&'b [u8]> {
4444
if id < self.segment_indices.len() as u32 {
4545
let (a, b) = self.segment_indices[id as usize];
@@ -104,7 +104,7 @@ impl std::ops::DerefMut for OwnedSegments {
104104
}
105105
}
106106

107-
unsafe impl crate::message::ReaderSegments for OwnedSegments {
107+
impl crate::message::ReaderSegments for OwnedSegments {
108108
fn get_segment<'a>(&'a self, id: u32) -> Option<&'a [u8]> {
109109
if id < self.segment_indices.len() as u32 {
110110
let (a, b) = self.segment_indices[id as usize];

0 commit comments

Comments
 (0)