Skip to content

Commit

Permalink
Use boxed slices instead of Vec in Error
Browse files Browse the repository at this point in the history
None of the data returned is meaningfully extensible, so reflect that in the types used.
  • Loading branch information
Ortham committed Jun 27, 2024
1 parent 191ebd9 commit 0eaa845
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ pub enum Error {
IoError(io::Error),
NoFilename(PathBuf),
ParsingIncomplete(MoreDataNeeded),
ParsingError(Vec<u8>, ParsingErrorKind),
DecodeError(Vec<u8>),
ParsingError(Box<[u8]>, ParsingErrorKind),
DecodeError(Box<[u8]>),
UnresolvedRecordIds(PathBuf),
PluginMetadataNotFound(String),
}
Expand All @@ -46,7 +46,7 @@ impl From<Err<nom::error::Error<&[u8]>>> for Error {
Error::ParsingIncomplete(MoreDataNeeded::Size(size))
}
Err::Error(err) | Err::Failure(err) => Error::ParsingError(
err.input.to_vec(),
err.input.into(),
ParsingErrorKind::GenericParserError(err.code.description().to_string()),
),
}
Expand Down
8 changes: 4 additions & 4 deletions src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ impl Plugin {
if subrecord.subrecord_type() == target_subrecord_type {
if subrecord.data().len() <= description_offset {
return Err(Error::ParsingError(
subrecord.data().to_vec(),
subrecord.data().into(),
ParsingErrorKind::SubrecordDataTooShort(description_offset),
));
}
Expand All @@ -298,7 +298,7 @@ impl Plugin {
return WINDOWS_1252
.decode_without_bom_handling_and_without_replacement(data)
.map(|s| Some(s.to_string()))
.ok_or(Error::DecodeError(data.to_vec()));
.ok_or(Error::DecodeError(data.into()));
}
}

Expand Down Expand Up @@ -729,9 +729,9 @@ fn masters(header_record: &Record) -> Result<Vec<String>, Error> {
WINDOWS_1252
.decode_without_bom_handling_and_without_replacement(d)
.map(|s| s.to_string())
.ok_or(Error::DecodeError(d.to_vec()))
.ok_or(Error::DecodeError(d.into()))
})
.collect::<Result<Vec<String>, Error>>()
.collect()
}

fn read_form_ids<R: BufRead + Seek>(reader: &mut R, game_id: GameId) -> Result<Vec<u32>, Error> {
Expand Down
2 changes: 1 addition & 1 deletion src/record.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ impl Record {
if &header_bytes[0..4] != expected_type {
// Take a copy of 16 bytes so the output includes the FormID.
return Err(Error::ParsingError(
header_bytes[..16].to_vec(),
header_bytes[..16].into(),
ParsingErrorKind::UnexpectedRecordType(expected_type.to_vec()),
));
}
Expand Down

0 comments on commit 0eaa845

Please sign in to comment.