Last active
March 14, 2020 23:56
-
-
Save mysteriouspants/c1fe4c3840a3058a5255e4eef97227dd to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct NoMemEntryStore<TSource: Read + Seek> { | |
/// information about the archive as a whole | |
archive: Archive, | |
/// the input source of the archive | |
source: TSource, | |
} | |
impl<TSource: Read + Seek> IndexStrategy for NoMemEntryStore<TSource> { | |
fn find_exact(&self, name: &str) -> Result<Option<&Entry>, EntryParseError> { | |
let archive = &self.archive; | |
let mut source = &self.source; | |
let opts = &opts_for_archive( | |
&archive.archive_version, &archive.archive_type | |
); | |
source.seek(SeekFrom::Start(archive.archive_start as u64))?; | |
for _i in 1 ..= archive.archive_size { | |
let entry = Entry::load_from(&mut source, opts)?; // E0277 source doesn't implement Read | |
if entry.0 == name { | |
return Ok(Some(&entry.1)); | |
} | |
} | |
return Ok(None); | |
} | |
} | |
// ... | |
impl Entry { | |
pub fn load_from( | |
source: &mut impl Read, | |
archive_opts: &ArchiveOpts, | |
) -> Result<(String, Entry), EntryParseError> { | |
let name = { | |
let mut buffer = vec![0; archive_opts.name_size]; | |
source.read_exact(&mut buffer)?; | |
cstring_from_bytes(&buffer)?.to_str()?.to_owned() | |
}; | |
let offset = decode_u32(&mut source)?; | |
let length = decode_u32(&mut source)?; | |
let unknown = decode_u32(&mut source)?; | |
return Ok((name, Entry { offset, length, unknown, })); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PS C:\Code\lod> cargo check | |
Checking mysteriouspants-lod v0.1.0 (C:\Code\lod\lod) | |
error[E0277]: the trait bound `&TSource: std::io::Read` is not satisfied | |
--> lod\src\lib.rs:200:42 | |
| | |
200 | let entry = Entry::load_from(&mut source, opts)?; | |
| -^^^^^^^^^^ | |
| | | |
| the trait `std::io::Read` is not implemented for `&TSource` | |
| help: consider removing 1 leading `&`-references | |
... | |
363 | pub fn load_from( | |
| --------- | |
364 | source: &mut impl Read, | |
| ---- required by this bound in `Entry::load_from` |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment