MCPcopy Create free account
hub / github.com/Lokathor/tinyvec / splice

Method splice

src/tinyvec.rs:1107–1144  ·  view source on GitHub ↗
(
    &mut self, range: R, replacement: I,
  )

Source from the content-addressed store, hash-verified

1105 /// ```
1106 #[inline]
1107 pub fn splice<R, I>(
1108 &mut self, range: R, replacement: I,
1109 ) -> TinyVecSplice<'_, A, core::iter::Fuse<I::IntoIter>>
1110 where
1111 R: RangeBounds<usize>,
1112 I: IntoIterator<Item = A::Item>,
1113 {
1114 use core::ops::Bound;
1115 let start = match range.start_bound() {
1116 Bound::Included(x) => *x,
1117 Bound::Excluded(x) => x.saturating_add(1),
1118 Bound::Unbounded => 0,
1119 };
1120 let end = match range.end_bound() {
1121 Bound::Included(x) => x.saturating_add(1),
1122 Bound::Excluded(x) => *x,
1123 Bound::Unbounded => self.len(),
1124 };
1125 assert!(
1126 start <= end,
1127 "TinyVec::splice> Illegal range, {} to {}",
1128 start,
1129 end
1130 );
1131 assert!(
1132 end <= self.len(),
1133 "TinyVec::splice> Range ends at {} but length is only {}!",
1134 end,
1135 self.len()
1136 );
1137
1138 TinyVecSplice {
1139 removal_start: start,
1140 removal_end: end,
1141 parent: self,
1142 replacement: replacement.into_iter().fuse(),
1143 }
1144 }
1145
1146 /// Wraps an array, using the given length as the starting length.
1147 ///

Callers 2

ArrayVec_spliceFunction · 0.45
TinyVec_spliceFunction · 0.45

Calls 4

start_boundMethod · 0.80
end_boundMethod · 0.80
lenMethod · 0.45
into_iterMethod · 0.45

Tested by 2

ArrayVec_spliceFunction · 0.36
TinyVec_spliceFunction · 0.36