Skip to content

Commit

Permalink
implement IndexMut for PushBytes
Browse files Browse the repository at this point in the history
  • Loading branch information
antonilol committed Aug 11, 2024
1 parent 71d760b commit 7c8601a
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion bitcoin/src/blockdata/script/push_bytes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ pub use self::primitive::*;
/// break invariants. Therefore auditing this module should be sufficient.
mod primitive {
use core::ops::{
Bound, Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
Bound, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo,
RangeToInclusive,
};

use super::PushBytesError;
Expand Down Expand Up @@ -95,6 +96,17 @@ mod primitive {
}
}
}

impl IndexMut<$type> for PushBytes {
#[inline]
#[track_caller]
fn index_mut(&mut self, index: $type) -> &mut Self::Output {
// SAFETY: Slicing can not make slices longer.
unsafe {
Self::from_mut_slice_unchecked(&mut self.0[index])
}
}
}
)*
}
}
Expand All @@ -117,6 +129,12 @@ mod primitive {
fn index(&self, index: usize) -> &Self::Output { &self.0[index] }
}

impl IndexMut<usize> for PushBytes {
#[inline]
#[track_caller]
fn index_mut(&mut self, index: usize) -> &mut Self::Output { &mut self.0[index] }
}

impl<'a> TryFrom<&'a [u8]> for &'a PushBytes {
type Error = PushBytesError;

Expand Down

0 comments on commit 7c8601a

Please sign in to comment.