Skip to content

Commit

Permalink
Implement validate_byte_slice instead of parse_byte_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Iain Ireland committed Sep 28, 2021
1 parent 5d52cb3 commit 3c46e87
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions components/uniset/src/ule.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ impl AsULE for GeneralSubcategory {
unsafe impl ULE for GeneralSubcategoryULE {
type Error = TryFromPrimitiveError<GeneralSubcategory>;

fn parse_byte_slice(bytes: &[u8]) -> Result<&[Self], Self::Error> {
fn validate_byte_slice(bytes: &[u8]) -> Result<(), Self::Error> {
// Validate the bytes
for b in bytes {
GeneralSubcategory::try_from(*b)?;
}
// Safe because Self is transparent over u8 and has been validated
Ok(unsafe { Self::from_byte_slice_unchecked(bytes) })
Ok(())
}

/// Invariant: must be safe to call when called on a slice that previously
Expand Down

0 comments on commit 3c46e87

Please sign in to comment.