@@ -314,7 +314,7 @@ impl<const N: usize> String<N> {
314
314
///
315
315
/// unsafe {
316
316
/// let vec = s.as_mut_vec();
317
- /// assert_eq!(&[104, 101, 108, 108, 111][..], &vec[..] );
317
+ /// assert_eq!(&b"hello", &vec);
318
318
///
319
319
/// vec.reverse();
320
320
/// }
@@ -325,6 +325,37 @@ impl<const N: usize> String<N> {
325
325
& mut self . vec
326
326
}
327
327
328
+ /// Returns a mutable reference to the contents of this `String`.
329
+ ///
330
+ /// # Safety
331
+ ///
332
+ /// This function is unsafe because it does not check that the bytes passed
333
+ /// to it are valid UTF-8. If this constraint is violated, it may cause
334
+ /// memory unsafety issues with future users of the `String`, as the rest of
335
+ /// the library assumes that `String`s are valid UTF-8.
336
+ ///
337
+ /// # Examples
338
+ ///
339
+ /// Basic usage:
340
+ ///
341
+ /// ```
342
+ /// use heapless::String;
343
+ ///
344
+ /// let mut s: String<8> = String::try_from("hello")?;
345
+ ///
346
+ /// unsafe {
347
+ /// let vec = s.as_mut_vec_view();
348
+ /// assert_eq!(&b"hello", &vec);
349
+ ///
350
+ /// vec.reverse();
351
+ /// }
352
+ /// assert_eq!(s, "olleh");
353
+ /// # Ok::<(), ()>(())
354
+ /// ```
355
+ pub unsafe fn as_mut_vec_view ( & mut self ) -> & mut VecView < u8 > {
356
+ & mut self . vec
357
+ }
358
+
328
359
/// Appends a given string slice onto the end of this `String`.
329
360
///
330
361
/// # Examples
@@ -592,7 +623,7 @@ impl StringView {
592
623
///
593
624
/// unsafe {
594
625
/// let vec = s.as_mut_vec();
595
- /// assert_eq!(&[104, 101, 108, 108, 111][..], &vec[..] );
626
+ /// assert_eq!(&b"hello", &vec);
596
627
///
597
628
/// vec.reverse();
598
629
/// }
0 commit comments