File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change @@ -255,6 +255,34 @@ impl<const N: usize> String<N> {
255
255
Some ( ch)
256
256
}
257
257
258
+ /// Removes a [`u8`] from this `String` at a byte position and returns it.
259
+ ///
260
+ /// Note: Because this shifts over the remaining elements, it has a
261
+ /// worst-case performance of *O*(*n*).
262
+ ///
263
+ /// # Panics
264
+ ///
265
+ /// Panics if `idx` is larger than or equal to the `String`'s length,
266
+ /// or if it does not lie on a [`char`] boundary.
267
+ ///
268
+ /// # Examples
269
+ ///
270
+ /// Basic usage:
271
+ ///
272
+ /// ```
273
+ /// use heapless::String;
274
+ ///
275
+ /// let mut s: String<8> = String::from("foo");
276
+ ///
277
+ /// assert_eq!(s.remove(0), b'f');
278
+ /// assert_eq!(s.remove(1), b'o');
279
+ /// assert_eq!(s.remove(0), b'o');
280
+ /// ```
281
+ #[ inline]
282
+ pub fn remove ( & mut self , index : usize ) -> u8 {
283
+ self . vec . remove ( index)
284
+ }
285
+
258
286
/// Truncates this `String`, removing all contents.
259
287
///
260
288
/// While this means the `String` will have a length of zero, it does not
@@ -708,4 +736,11 @@ mod tests {
708
736
assert_eq ! ( 0 , s. len( ) ) ;
709
737
assert_eq ! ( 8 , s. capacity( ) ) ;
710
738
}
739
+
740
+ #[ test]
741
+ fn remove ( ) {
742
+ let mut s: String < 8 > = String :: from ( "foo" ) ;
743
+ assert_eq ! ( b'f' , s. remove( 0 ) ) ;
744
+ assert_eq ! ( "oo" , s. as_str( ) ) ;
745
+ }
711
746
}
You can’t perform that action at this time.
0 commit comments