@@ -87,14 +87,15 @@ impl ReaderOptions {
87
87
}
88
88
89
89
/// An object that manages the buffers underlying a Cap'n Proto message reader.
90
- pub unsafe trait ReaderSegments {
90
+ pub trait ReaderSegments {
91
91
/// Gets the segment with index `idx`. Returns `None` if `idx` is out of range.
92
92
///
93
93
/// The segment must be 8-byte aligned or the "unaligned" feature must
94
94
/// be enabled in the capnp crate. (Otherwise reading the segment will return an error.)
95
95
///
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`.)
98
99
fn get_segment < ' a > ( & ' a self , idx : u32 ) -> Option < & ' a [ u8 ] > ;
99
100
100
101
/// Gets the number of segments.
@@ -119,7 +120,7 @@ impl <'a> SegmentArray<'a> {
119
120
}
120
121
}
121
122
122
- unsafe impl < ' b > ReaderSegments for SegmentArray < ' b > {
123
+ impl < ' b > ReaderSegments for SegmentArray < ' b > {
123
124
fn get_segment < ' a > ( & ' a self , id : u32 ) -> Option < & ' a [ u8 ] > {
124
125
self . segments . get ( id as usize ) . map ( |slice| * slice)
125
126
}
@@ -129,7 +130,7 @@ unsafe impl <'b> ReaderSegments for SegmentArray<'b> {
129
130
}
130
131
}
131
132
132
- unsafe impl < ' b > ReaderSegments for [ & ' b [ u8 ] ] {
133
+ impl < ' b > ReaderSegments for [ & ' b [ u8 ] ] {
133
134
fn get_segment < ' a > ( & ' a self , id : u32 ) -> Option < & ' a [ u8 ] > {
134
135
self . get ( id as usize ) . map ( |slice| * slice)
135
136
}
@@ -382,7 +383,7 @@ impl <A> Builder<A> where A: Allocator {
382
383
}
383
384
}
384
385
385
- unsafe impl < A > ReaderSegments for Builder < A > where A : Allocator {
386
+ impl < A > ReaderSegments for Builder < A > where A : Allocator {
386
387
fn get_segment < ' a > ( & ' a self , id : u32 ) -> Option < & ' a [ u8 ] > {
387
388
self . get_segments_for_output ( ) . get ( id as usize ) . map ( |x| * x)
388
389
}
0 commit comments