Skip to content

Commit 4a1f8f0

Browse files
committed
Allow PDB to impl Send.
1 parent b052964 commit 4a1f8f0

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/msf/mod.rs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,14 @@ enum StreamTable<'s> {
5555

5656
// Given the table location, we can access the stream table itself
5757
Available {
58-
stream_table_view: Box<dyn SourceView<'s>>,
58+
stream_table_view: Box<dyn SourceView<'s> + Send>,
5959
},
6060
}
6161

62-
fn view<'s>(source: &mut dyn Source<'s>, page_list: &PageList) -> Result<Box<dyn SourceView<'s>>> {
62+
fn view<'s>(
63+
source: &mut dyn Source<'s>,
64+
page_list: &PageList,
65+
) -> Result<Box<dyn SourceView<'s> + Send + Sync>> {
6366
// view it
6467
let view = source.view(page_list.source_slices())?;
6568

@@ -119,8 +122,11 @@ mod big {
119122
stream_table: StreamTable<'s>,
120123
}
121124

122-
impl<'s, S: Source<'s>> BigMSF<'s, S> {
123-
pub fn new(source: S, header_view: Box<dyn SourceView<'_>>) -> Result<BigMSF<'s, S>> {
125+
impl<'s, S: Source<'s> + Send> BigMSF<'s, S> {
126+
pub fn new(
127+
source: S,
128+
header_view: Box<dyn SourceView<'_> + Send>,
129+
) -> Result<BigMSF<'s, S>> {
124130
let mut buf = ParseBuffer::from(header_view.as_slice());
125131
let header: RawHeader = buf.parse()?;
126132

@@ -316,7 +322,7 @@ mod big {
316322
}
317323
}
318324

319-
impl<'s, S: Source<'s>> Msf<'s, S> for BigMSF<'s, S> {
325+
impl<'s, S: Source<'s> + Send> Msf<'s, S> for BigMSF<'s, S> {
320326
fn get(&mut self, stream_number: u32, limit: Option<usize>) -> Result<Stream<'s>> {
321327
// look up the stream
322328
let mut page_list = self.look_up_stream(stream_number)?;
@@ -345,7 +351,7 @@ mod small {
345351
/// Represents a single Stream within the multi-stream file.
346352
#[derive(Debug)]
347353
pub struct Stream<'s> {
348-
source_view: Box<dyn SourceView<'s>>,
354+
source_view: Box<dyn SourceView<'s> + Send + Sync>,
349355
}
350356

351357
impl<'s> Stream<'s> {
@@ -380,7 +386,9 @@ fn header_matches(actual: &[u8], expected: &[u8]) -> bool {
380386
actual.len() >= expected.len() && &actual[0..expected.len()] == expected
381387
}
382388

383-
pub fn open_msf<'s, S: Source<'s> + 's>(mut source: S) -> Result<Box<dyn Msf<'s, S> + 's>> {
389+
pub fn open_msf<'s, S: Source<'s> + Send + 's>(
390+
mut source: S,
391+
) -> Result<Box<dyn Msf<'s, S> + Send + 's>> {
384392
// map the header
385393
let mut header_location = PageList::new(4096);
386394
header_location.push(0);

src/pdb.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const IPI_STREAM: u32 = 4;
3434
#[derive(Debug)]
3535
pub struct PDB<'s, S> {
3636
/// `msf` provides access to the underlying data streams
37-
msf: Box<dyn Msf<'s, S> + 's>,
37+
msf: Box<dyn Msf<'s, S> + Send + 's>,
3838

3939
/// Memoize the `dbi::Header`, since it contains stream numbers we sometimes need
4040
dbi_header: Option<DBIHeader>,
@@ -43,7 +43,15 @@ pub struct PDB<'s, S> {
4343
dbi_extra_streams: Option<DBIExtraStreams>,
4444
}
4545

46-
impl<'s, S: Source<'s> + 's> PDB<'s, S> {
46+
// Assert that the PDB type is Send.
47+
const _: fn() = || {
48+
fn assert<T: ?Sized + Send>() {}
49+
// Use a dummy *const () for `S` as that will be !Send and !Sync.
50+
// In practice to make a PDB `S` will need to be Send, but it doesn't matter here.
51+
assert::<PDB<*const ()>>();
52+
};
53+
54+
impl<'s, S: Source<'s> + Send + 's> PDB<'s, S> {
4755
/// Create a new `PDB` for a `Source`.
4856
///
4957
/// `open()` accesses enough of the source file to find the MSF stream table. This usually
@@ -529,7 +537,7 @@ impl StreamIndex {
529537
/// * `Error::PageReferenceOutOfRange` if the PDB file seems corrupt
530538
pub fn get<'s, S>(self, pdb: &mut PDB<'s, S>) -> Result<Option<Stream<'s>>>
531539
where
532-
S: Source<'s> + 's,
540+
S: Source<'s> + Send + 's,
533541
{
534542
pdb.raw_stream(self)
535543
}

src/source.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ pub trait Source<'s>: fmt::Debug {
5151
///
5252
/// Note that the SourceView's as_slice() method cannot fail, so `view()` is the time to raise
5353
/// IO errors.
54-
fn view(&mut self, slices: &[SourceSlice]) -> Result<Box<dyn SourceView<'s>>, io::Error>;
54+
fn view(
55+
&mut self,
56+
slices: &[SourceSlice],
57+
) -> Result<Box<dyn SourceView<'s> + Send + Sync>, io::Error>;
5558
}
5659

5760
/// An owned, droppable, read-only view of the source file which can be referenced as a byte slice.
@@ -81,7 +84,10 @@ impl<'s, T> Source<'s> for T
8184
where
8285
T: io::Read + io::Seek + fmt::Debug + 's,
8386
{
84-
fn view(&mut self, slices: &[SourceSlice]) -> Result<Box<dyn SourceView<'s>>, io::Error> {
87+
fn view(
88+
&mut self,
89+
slices: &[SourceSlice],
90+
) -> Result<Box<dyn SourceView<'s> + Send + Sync>, io::Error> {
8591
let len = slices.iter().fold(0, |acc, s| acc + s.size);
8692

8793
let mut v = ReadView {

0 commit comments

Comments
 (0)