File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -172,6 +172,25 @@ impl AsciiString {
172172 self . vec . extend ( string. chars ( ) )
173173 }
174174
175+ /// Inserts the given ASCII string at the given place in this ASCII string buffer.
176+ ///
177+ /// # Panics
178+ ///
179+ /// Panics if `idx` is larger than the `AsciiString`'s length.
180+ ///
181+ /// # Examples
182+ /// ```
183+ /// # use ascii::{AsciiString, AsAsciiStr};
184+ /// use std::str::FromStr;
185+ /// let mut s = AsciiString::from_str("abc").unwrap();
186+ /// s.insert_str(1, "def".as_ascii_str().unwrap());
187+ /// assert_eq!(&*s, "adefbc");
188+ #[ inline]
189+ pub fn insert_str ( & mut self , idx : usize , string : & AsciiStr ) {
190+ self . vec . reserve ( string. len ( ) ) ;
191+ self . vec . splice ( idx..idx, string. into_iter ( ) . copied ( ) ) ;
192+ }
193+
175194 /// Returns the number of bytes that this ASCII string buffer can hold without reallocating.
176195 ///
177196 /// # Examples
You can’t perform that action at this time.
0 commit comments