Skip to content

Commit 7c8601a

Browse files
committed
implement IndexMut for PushBytes
1 parent 71d760b commit 7c8601a

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

bitcoin/src/blockdata/script/push_bytes.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ pub use self::primitive::*;
1515
/// break invariants. Therefore auditing this module should be sufficient.
1616
mod primitive {
1717
use core::ops::{
18-
Bound, Index, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo, RangeToInclusive,
18+
Bound, Index, IndexMut, Range, RangeFrom, RangeFull, RangeInclusive, RangeTo,
19+
RangeToInclusive,
1920
};
2021

2122
use super::PushBytesError;
@@ -95,6 +96,17 @@ mod primitive {
9596
}
9697
}
9798
}
99+
100+
impl IndexMut<$type> for PushBytes {
101+
#[inline]
102+
#[track_caller]
103+
fn index_mut(&mut self, index: $type) -> &mut Self::Output {
104+
// SAFETY: Slicing can not make slices longer.
105+
unsafe {
106+
Self::from_mut_slice_unchecked(&mut self.0[index])
107+
}
108+
}
109+
}
98110
)*
99111
}
100112
}
@@ -117,6 +129,12 @@ mod primitive {
117129
fn index(&self, index: usize) -> &Self::Output { &self.0[index] }
118130
}
119131

132+
impl IndexMut<usize> for PushBytes {
133+
#[inline]
134+
#[track_caller]
135+
fn index_mut(&mut self, index: usize) -> &mut Self::Output { &mut self.0[index] }
136+
}
137+
120138
impl<'a> TryFrom<&'a [u8]> for &'a PushBytes {
121139
type Error = PushBytesError;
122140

0 commit comments

Comments
 (0)