### Trim Start Matches
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/smol_str/struct.SmolStr
Removes all prefixes that match a given pattern repeatedly.
```APIDOC
## POST /websites/rs_smol_str_0_3_2/trim_start_matches
### Description
Returns a string slice with all prefixes that match a pattern repeatedly removed. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches.
### Method
POST
### Endpoint
`/websites/rs_smol_str_0_3_2/trim_start_matches`
### Parameters
#### Query Parameters
- **pat** (string | char[] | function) - Required - The pattern to match for trimming from the start.
### Request Body
```json
{
"text": "string",
"pattern": "any"
}
```
### Request Example
```json
{
"text": "11foo1bar11",
"pattern": "1"
}
```
### Response
#### Success Response (200)
- **string** - The string slice with matching prefixes removed.
#### Response Example
```json
{
"result": "foo1bar11"
}
```
```
--------------------------------
### Trim Start Matches
Source: https://docs.rs/smol_str/0.3.2/smol_str/struct.SmolStr
Removes all prefixes that match a given pattern repeatedly.
```APIDOC
## trim_start_matches
### Description
Returns a string slice with all prefixes that match a pattern repeatedly removed.
### Method
`&self` (implicit)
### Endpoint
N/A (method on string slice)
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
- **pat** (P: Pattern) - Required - The pattern to match for trimming.
### Request Example
```rust
assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11");
assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12");
```
### Response
#### Success Response (200)
- **&str** - The string slice with matching prefixes removed.
#### Response Example
```rust
"foo1bar11"
```
```
--------------------------------
### starts_with
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/struct.SmolStr
Checks if a string slice starts with a given pattern.
```APIDOC
## POST /starts_with
### Description
Checks if a string slice starts with a given pattern. The pattern can be a substring, character, or a slice of characters.
### Method
POST
### Endpoint
/starts_with
### Parameters
#### Request Body
- **text** (string) - Required - The string slice to check.
- **pattern** (string) - Required - The pattern to check for at the beginning.
### Request Example
```json
{
"text": "bananas",
"pattern": "bana"
}
```
### Response
#### Success Response (200)
- **result** (boolean) - True if the string slice starts with the pattern, false otherwise.
#### Response Example
```json
{
"result": true
}
```
```
--------------------------------
### Trim Start Matches
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/struct.SmolStr
Removes leading characters that match a given pattern.
```APIDOC
## GET /websites/rs_smol_str_0_3_2/trim_start_matches
### Description
Returns a string slice with all prefixes that match a pattern repeatedly removed. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches.
### Method
GET
### Endpoint
`/websites/rs_smol_str_0_3_2/trim_start_matches`
### Parameters
#### Path Parameters
None
#### Query Parameters
- **pat** (Pattern) - Required - The pattern to match for trimming from the start.
#### Request Body
None
### Request Example
None
### Response
#### Success Response (200)
- **string** - The string slice with matching prefixes removed.
#### Response Example
```
"foo1bar11"
```
```
--------------------------------
### SmolStr String Repetition Example (Rust)
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/smol_str/struct.SmolStr
Demonstrates how to repeat a SmolStr string a specified number of times. It also shows a case that will panic due to overflow if the repeated string exceeds available memory.
```rust
assert_eq!("abc".repeat(4), String::from("abcabcabcabc"));
// this will panic at runtime
// let huge = "0123456789abcdef".repeat(usize::MAX);
```
--------------------------------
### Trim Start Matches Pattern
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/struct.SmolStr
Returns a string slice with all prefixes that match a pattern repeatedly removed. The pattern can be a &str, char, slice of chars, or a function/closure.
```APIDOC
## POST /websites/rs_smol_str_0_3_2/trim_start_matches
### Description
Returns a string slice with all prefixes that match a pattern repeatedly removed.
### Method
POST
### Endpoint
`/websites/rs_smol_str_0_3_2/trim_start_matches`
### Parameters
#### Query Parameters
- **pattern** (string) - Required - The pattern to match for trimming prefixes (e.g., a character like '1', or a string like "12").
#### Request Body
- **input_string** (string) - Required - The string to trim.
### Request Example
```json
{
"input_string": "12foo1bar11",
"pattern": "12"
}
```
### Response
#### Success Response (200)
- **trimmed_string** (string) - The string slice with matching prefixes removed.
#### Response Example
```json
{
"trimmed_string": "foo1bar11"
}
```
```
--------------------------------
### Escape Characters in Rust
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/struct.SmolStr
These Rust examples demonstrate the use of `escape_debug`, `escape_default`, and `escape_unicode` to escape characters within a string. They show how to iterate through the escaped characters or use them directly in `println!`. This is helpful when dealing with special characters or when displaying strings in a debug environment.
```rust
for c in "❤\n!".escape_debug() {
print!("{c}");
}
println!();
println!("{{}}", "❤\n!".escape_debug());
assert_eq!("❤\n!".escape_debug().to_string(), "❤\\n!");
for c in "❤\n!".escape_default() {
print!("{c}");
}
println!();
println!("{{}}", "❤\n!".escape_default());
assert_eq!("❤\n!".escape_default().to_string(), "\\u{{2764}}\\n!");
```
--------------------------------
### starts_with
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/smol_str/struct.SmolStr
Checks if the string slice starts with a given pattern. The pattern can be a `&str`, `char`, a slice of `char`s, or a closure.
```APIDOC
## starts_with
### Description
Returns `true` if the given pattern matches a prefix of this string slice. Returns `false` if it does not. The pattern can be a `&str`, in which case this function will return true if the `&str` is a prefix of this string slice. The pattern can also be a `char`, a slice of `char`s, or a function or closure that determines if a character matches.
### Method
```
fn starts_with
(&self, pat: P) -> bool where P: Pattern
```
### Parameters
#### Query Parameters
- **pat** (Pattern) - Required - The pattern to check against the prefix of the string slice.
### Request Example
```rust
let bananas = "bananas";
assert!(bananas.starts_with("bana"));
assert!(!bananas.starts_with("nana"));
// Note that both of these assert successfully.
assert!(bananas.starts_with(&['b', 'a', 'n', 'a']));
assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
```
### Response
- **bool** (bool) - `true` if the string slice starts with the pattern, `false` otherwise.
```
--------------------------------
### Convert String Slice to Bytes in Rust
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Demonstrates how to convert a string slice into a byte slice using the `as_bytes` method. This is useful for low-level byte manipulation or when interacting with APIs that expect byte arrays. The example shows asserting equality between the original byte representation and the converted bytes.
```rust
let bytes = "bors".as_bytes();
assert_eq!(b"bors", bytes);
```
--------------------------------
### Escape string for default representation (Rust)
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/smol_str/struct.SmolStr
Demonstrates the `escape_default` method, which provides an iterator for escaping characters according to `char::escape_default`. Examples cover iterator usage, direct printing, and string conversion.
```rust
for c in "❤\n!".escape_default() {
print!("{c}");
}
println!();
```
```rust
println!("{}", "❤\n!".escape_default());
```
```rust
assert_eq!("❤\n!".escape_default().to_string(), "\u{2764}\n!");
```
--------------------------------
### Create a new SmolStrBuilder in Rust
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/struct.SmolStrBuilder
Provides a constant function `new` to create an empty SmolStrBuilder. This is the starting point for building a `SmolStr` using the builder pattern.
```Rust
pub const fn new() -> Self
```
--------------------------------
### Rust: Escaping String Characters for Debug, Default, and Unicode
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Demonstrates Rust's `escape_debug`, `escape_default`, and `escape_unicode` methods for creating iterators that yield escaped versions of string characters. Examples show usage as iterators, with `println!`, and converting to strings.
```rust
for c in "❤\n!".escape_debug() {
print!("{c}");
}
println!();
```
```rust
println!("{}", "❤\n!".escape_debug());
```
```rust
assert_eq!("❤\n!".escape_debug().to_string(), "❤\\n!");
```
```rust
for c in "❤\n!".escape_default() {
print!("{c}");
}
println!();
```
```rust
println!("{}", "❤\n!".escape_default());
```
```rust
assert_eq!("❤\n!".escape_default().to_string(), "\\u{2764}\\n!");
```
```rust
for c in "❤\n!".escape_unicode() {
print!("{c}");
}
println!();
```
--------------------------------
### Rust: Trimming ASCII Whitespace from Strings
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Provides examples of Rust's `trim_ascii_start`, `trim_ascii_end`, and `trim_ascii` methods for removing ASCII whitespace from the beginning, end, or both ends of a string slice, respectively. Whitespace is defined by `u8::is_ascii_whitespace`.
```rust
assert_eq!(" \t \u{3000}hello world\n".trim_ascii_start(), "\u{3000}hello world\n");
assert_eq!(" ".trim_ascii_start(), "");
assert_eq!("".trim_ascii_start(), "");
```
```rust
assert_eq!("\r hello world\u{3000}\n ".trim_ascii_end(), "\r hello world\u{3000}");
assert_eq!(" ".trim_ascii_end(), "");
assert_eq!("".trim_ascii_end(), "");
```
```rust
assert_eq!("\r hello world\n ".trim_ascii(), "hello world");
assert_eq!(" ".trim_ascii(), "");
assert_eq!("".trim_ascii(), "");
```
--------------------------------
### Rust: Checking for ASCII Characters with `is_ascii`
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Shows how to use the `is_ascii` method in Rust to determine if all characters in a string slice fall within the ASCII range. Examples include both purely ASCII strings and strings containing non-ASCII characters.
```rust
let ascii = "hello!\n";
let non_ascii = "Grüße, Jürgen ❤";
assert!(ascii.is_ascii());
assert!(!non_ascii.is_ascii());
```
--------------------------------
### Deref to str: String Length Example
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/struct.SmolStr
Demonstrates how to get the length of a string slice obtained via Deref coercion from SmolStr. The length is in bytes.
```Rust
let len = "foo".len();
assert_eq!(3, len);
assert_eq!("ƒoo".len(), 4); // fancy f!
assert_eq!("ƒoo".chars().count(), 3);
```
--------------------------------
### Escape string for debug representation (Rust)
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/smol_str/struct.SmolStr
Explains how to use `escape_debug` to get an iterator that escapes characters for debugging purposes, similar to `char::escape_debug`. Examples show using the iterator directly and converting to a string.
```rust
for c in "❤\n!".escape_debug() {
print!("{c}");
}
println!();
```
```rust
println!("{}", "❤\n!".escape_debug());
```
```rust
assert_eq!("❤\n!".escape_debug().to_string(), "❤\\n!");
```
--------------------------------
### Get ASCII Characters Slice (Experimental) in Rust
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/smol_str/struct.SmolStr
Provides examples for experimental nightly-only APIs `as_ascii` and `as_ascii_unchecked`. `as_ascii` safely returns an `Option<&[AsciiChar]>` if the string is purely ASCII, while `as_ascii_unchecked` provides direct access without a safety check (requires `unsafe`).
```rust
// Note: This is an experimental API and requires a nightly compiler.
// let ascii_slice = "hello".as_ascii(); // Returns Some(&[AsciiChar]) if valid ASCII
// let non_ascii_slice = "Grüße".as_ascii(); // Returns None
```
```rust
// Note: This is an experimental API and requires a nightly compiler and unsafe block.
// unsafe {
// let ascii_unchecked = "hello".as_ascii_unchecked(); // Returns &[AsciiChar]
// }
```
--------------------------------
### SmolStr Conversions
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/struct.SmolStr
Demonstrates conversions to and from SmolStr for different string types like &str, Arc, Box, Cow<'a, str>, String, and SmolStrBuilder.
```APIDOC
## SmolStr Conversions
This section details the various ways SmolStr can be created from other string types and how SmolStr itself can be converted into other string types.
### From<&str>
Converts a string slice (`&str`) into a `SmolStr`.
- **Method**: `impl From<&str> for SmolStr`
- **Function**: `fn from(s: &str) -> SmolStr`
### From>
Converts an `Arc` into a `SmolStr`.
- **Method**: `impl From> for SmolStr`
- **Function**: `fn from(s: Arc) -> SmolStr`
### From>
Converts a `Box` into a `SmolStr`.
- **Method**: `impl From> for SmolStr`
- **Function**: `fn from(s: Box) -> SmolStr`
### From<'a, Cow<'a, str>>
Converts a `Cow<'a, str>` (Clone-on-Write string) into a `SmolStr`.
- **Method**: `impl<'a> From> for SmolStr`
- **Function**: `fn from(s: Cow<'a, str>) -> SmolStr`
### From for Arc
Converts a `SmolStr` into an `Arc`.
- **Method**: `impl From for Arc`
- **Function**: `fn from(text: SmolStr) -> Self`
### From for String
Converts a `SmolStr` into a `String`.
- **Method**: `impl From for String`
- **Function**: `fn from(text: SmolStr) -> Self`
### From
Converts a `SmolStrBuilder` into a `SmolStr`.
- **Method**: `impl From for SmolStr`
- **Function**: `fn from(value: SmolStrBuilder) -> Self`
### From
Converts a `String` into a `SmolStr`.
- **Method**: `impl From for SmolStr`
- **Function**: `fn from(text: String) -> Self`
```
--------------------------------
### Constructing SmolStr: Inline, Static, and General
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/smol_str/struct.SmolStr
Provides methods to create SmolStr instances. `new_inline` constructs from a &str without allocation (panics if len > 23). `new_static` creates from a 'static str without allocation. `new` creates from any &str, heap-allocating if necessary.
```rust
pub const fn new_inline(text: &str) -> SmolStr
```
```rust
pub const fn new_static(text: &'static str) -> SmolStr
```
```rust
pub fn new(text: impl AsRef) -> SmolStr
```
--------------------------------
### get - Get Subslice Safely
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/struct.SmolStr
Returns a subslice of `str` if the indices are valid and on UTF-8 sequence boundaries. Returns `None` otherwise.
```APIDOC
## pub fn get(&self, i: I) -> Option<&>::Output>
### Description
Returns a subslice of `str`. This is the non-panicking alternative to indexing the `str`. Returns `None` whenever equivalent indexing operation would panic.
### Method
GET
### Endpoint
N/A (Method on `str` type)
### Parameters
* `i` (Range or `usize`): The range or index to slice.
### Request Example
```rust
let v = String::from("🗻∈🌏");
assert_eq!(Some("🗻"), v.get(0..4));
// indices not on UTF-8 sequence boundaries
assert!(v.get(1..).is_none());
assert!(v.get(..8).is_none());
// out of bounds
assert!(v.get(..42).is_none());
```
### Response
#### Success Response (N/A)
Returns `Some(&str)` if the slice is valid, `None` otherwise.
#### Response Example
```rust
// For v.get(0..4) on "🗻∈🌏"
Some("🗻")
// For v.get(1..)
None
```
```
--------------------------------
### split_at()
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/smol_str/struct.SmolStr
Divides one string slice into two at an index. The argument, mid, should be a byte offset from the start of the string. The two slices returned go from the start of the string slice to mid, and from mid to the end of the string slice.
```APIDOC
## split_at()
### Description
Divides one string slice into two at an index. The argument, `mid`, should be a byte offset from the start of the string.
### Method
`pub fn split_at(&self, mid: usize) -> (&str, &str)`
### Endpoint
N/A
### Parameters
N/A
### Request Example
N/A
### Response
N/A
```
--------------------------------
### SmolStrBuilder Clone and Default Implementations
Source: https://docs.rs/smol_str/0.3.2/smol_str/struct.SmolStrBuilder
Shows that `SmolStrBuilder` implements `Clone` for creating copies and `Default` for easily creating a default, empty instance. `clone_from` is also provided for efficient in-place cloning.
```rust
impl Clone for SmolStrBuilder
fn clone(&self) -> SmolStrBuilder
fn clone_from(&mut self, source: &Self)
impl Default for SmolStrBuilder
fn default() -> SmolStrBuilder
```
--------------------------------
### Deref Implementation: len and is_empty Examples
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/smol_str/struct.SmolStr
Demonstrates the `len` and `is_empty` methods inherited from the `Deref` trait for `&str`. `len` returns the byte length, and `is_empty` checks if the string has zero bytes. Examples show byte length for ASCII and Unicode characters.
```rust
let len = "foo".len();
assert_eq!(3, len);
assert_eq!("ƒoo".len(), 4); // fancy f!
assert_eq!("ƒoo".chars().count(), 3);
```
```rust
let s = "";
assert!(s.is_empty());
let s = "not empty";
assert!(!s.is_empty());
```
--------------------------------
### Repeat String: Basic Usage
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Demonstrates the basic usage of the `repeat` method for strings, showing how to create a new string by concatenating the original string a specified number of times. This method is straightforward and does not have complex dependencies.
```rust
assert_eq!("abc".repeat(4), String::from("abcabcabcabc"));
```
--------------------------------
### Create and Manipulate SmolStrBuilder
Source: https://docs.rs/smol_str/0.3.2/smol_str/struct.SmolStrBuilder
Provides methods for interacting with the SmolStrBuilder. `new()` creates an empty builder, `push()` appends a single character, and `push_str()` appends a string slice. The `finish()` method constructs the final SmolStr object.
```rust
pub const fn new() -> Self
pub fn finish(&self) -> SmolStr
pub fn push(&mut self, c: char)
pub fn push_str(&mut self, s: &str)
```
--------------------------------
### Check if String Starts With Prefix (Rust)
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Returns `true` if the string slice starts with the given pattern, and `false` otherwise. The pattern can be a `&str`, `char`, slice of `char`s, or a predicate function. For `&str` patterns, it checks the entire prefix. For `char` or predicate patterns, it only checks the first character.
```Rust
let bananas = "bananas";
assert!(bananas.starts_with("bana"));
assert!(!bananas.starts_with("nana"));
```
```Rust
let bananas = "bananas";
// Note that both of these assert successfully.
assert!(bananas.starts_with(&['b', 'a', 'n', 'a']));
assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
```
--------------------------------
### Trim Start Whitespace API
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/struct.SmolStr
Removes leading whitespace from a string slice.
```APIDOC
## GET /string/trim_start
### Description
Returns a string slice with leading whitespace removed. Whitespace is defined according to the Unicode Derived Core Property `White_Space`, which includes newlines.
### Method
GET
### Endpoint
`/string/trim_start`
### Response
#### Success Response (200)
- **trimmed_string** (string) - The string slice with leading whitespace removed.
#### Response Example
```json
{
"trimmed_string": "Hello\tworld\t\n"
}
```
```
--------------------------------
### SmolStrBuilder Trait Implementations
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/struct.SmolStrBuilder
Details various trait implementations for SmolStrBuilder, enhancing its usability. This includes `Clone` for duplication, `Debug` for formatting, `Default` for creating a default instance, `From for SmolStr` for type conversion, `PartialEq` for comparison, and `Write` for I/O operations.
```rust
impl Clone for SmolStrBuilder
fn clone(&self) -> SmolStrBuilder
Returns a duplicate of the value.
```
```rust
impl Debug for SmolStrBuilder
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter.
```
```rust
impl Default for SmolStrBuilder
fn default() -> SmolStrBuilder
Returns the “default value” for a type.
```
```rust
impl From for SmolStr
fn from(value: SmolStrBuilder) -> Self
Converts to this type from the input type.
```
```rust
impl PartialEq for SmolStrBuilder
fn eq(&self, other: &SmolStrBuilder) -> bool
Tests for `self` and `other` values to be equal, and is used by `==`.
```
```rust
impl Write for SmolStrBuilder
fn write_str(&mut self, s: &str) -> Result
Writes a string slice into this writer, returning whether the write succeeded.
```
```rust
impl Write for SmolStrBuilder
fn write_char(&mut self, c: char) -> Result<(), Error>
Writes a `char` into this writer, returning whether the write succeeded.
```
```rust
impl Write for SmolStrBuilder
fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>
Glue for usage of the `write!` macro with implementors of this trait.
```
--------------------------------
### SmolStr Creation Methods
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/src/smol_str/lib.rs
Demonstrates how to create SmolStr instances using different strategies: `new_inline` for small, stack-allocated strings (up to 23 bytes), `new_static` for immutable string literals without allocation, and `new` for general string conversion (heap-allocating if necessary).
```rust
/// Constructs an inline variant of `SmolStr`.
///
/// This never allocates.
///
/// # Panics
///
/// Panics if `text.len() > 23`.
#[inline]
pub const fn new_inline(text: &str) -> SmolStr {
assert!(text.len() <= INLINE_CAP); // avoids bounds checks in loop
let text = text.as_bytes();
let mut buf = [0; INLINE_CAP];
let mut i = 0;
while i < text.len() {
buf[i] = text[i];
i += 1
}
SmolStr(Repr::Inline {
// SAFETY: We know that `len` is less than or equal to the maximum value of `InlineSize`
// as we asserted it.
len: unsafe { InlineSize::transmute_from_u8(text.len() as u8) },
buf,
})
}
/// Constructs a `SmolStr` from a statically allocated string.
///
/// This never allocates.
#[inline(always)]
pub const fn new_static(text: &'static str) -> SmolStr {
// NOTE: this never uses the inline storage; if a canonical
// representation is needed, we could check for `len() < INLINE_CAP`
// and call `new_inline`, but this would mean an extra branch.
SmolStr(Repr::Static(text))
}
/// Constructs a `SmolStr` from a `str`, heap-allocating if necessary.
#[inline(always)]
pub fn new(text: impl AsRef) -> SmolStr {
SmolStr(Repr::new(text.as_ref()))
}
```
--------------------------------
### Safely Get Subslice of String Slice in Rust
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/smol_str/struct.SmolStr
Shows how to safely retrieve a subslice of a string slice using the `get` method. This method returns an `Option<&str>`, providing `None` if the requested range is invalid (e.g., out of bounds or not on a UTF-8 sequence boundary), thus preventing panics. It's ideal for scenarios where indices might be unpredictable.
```rust
let v = String::from("🗻∈🌏");
assert_eq!(Some("🗻"), v.get(0..4));
// indices not on UTF-8 sequence boundaries
assert!(v.get(1..).is_none());
assert!(v.get(..8).is_none());
// out of bounds
assert!(v.get(..42).is_none());
```
--------------------------------
### SmolStr Serialization
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/smol_str/struct.SmolStr
Documentation for serializing SmolStr instances using the Serde library.
```APIDOC
## SmolStr Serialization
This section details the serialization capabilities for SmolStr instances.
### `impl Serialize for SmolStr`
Available on **crate feature `serde`** only.
#### `fn serialize(&self, serializer: S) -> Result`
where S: Serializer,
Serialize this value into the given Serde serializer.
```
--------------------------------
### SmolStr: Get Length
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/src/smol_str/lib.rs
Returns the length of the `SmolStr` in bytes. This is a constant-time operation.
```rust
pub fn len(&self) -> usize {
self.0.len()
}
```
--------------------------------
### Check if String Starts With Substring
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/smol_str/struct.SmolStr
Checks if the string slice begins with the given pattern (substring).
```APIDOC
## POST /string/starts_with
### Description
Returns `true` if the given pattern matches a prefix of this string slice, `false` otherwise.
### Method
POST
### Endpoint
/string/starts_with
### Parameters
#### Request Body
- **input_string** (string) - Required - The string to check.
- **pattern** (string) - Required - The prefix pattern to look for.
### Request Example
{
"input_string": "bananas",
"pattern": "bana"
}
### Response
#### Success Response (200)
- **result** (boolean) - `true` if the string starts with the pattern, `false` otherwise.
#### Response Example
{
"result": true
}
```
--------------------------------
### SmolStrBuilder Methods
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/src/smol_str/lib.rs
Provides methods for building a SmolStr efficiently. `SmolStrBuilder::new()` creates an empty builder, `finish()` constructs the final SmolStr, `push()` appends a character, and `push_str()` appends a string slice. These methods handle both inline and heap allocations.
```rust
pub const fn new() -> Self {
Self(SmolStrBuilderRepr::Inline {
buf: [0; INLINE_CAP],
len: 0,
})
}
pub fn finish(&self) -> SmolStr {
SmolStr(match &self.0 {
&SmolStrBuilderRepr::Inline { len, buf } => {
debug_assert!(len <= INLINE_CAP);
Repr::Inline {
// SAFETY: We know that `value.len` is less than or equal to the maximum value of `InlineSize`
len: unsafe { InlineSize::transmute_from_u8(len as u8) },
buf,
}
}
SmolStrBuilderRepr::Heap(heap) => Repr::new(heap),
})
}
pub fn push(&mut self, c: char) {
match &mut self.0 {
SmolStrBuilderRepr::Inline { len, buf } => {
let char_len = c.len_utf8();
let new_len = *len + char_len;
if new_len <= INLINE_CAP {
c.encode_utf8(&mut buf[*len..]);
*len += char_len;
} else {
let mut heap = String::with_capacity(new_len);
// copy existing inline bytes over to the heap
// SAFETY: inline data is guaranteed to be valid utf8 for `old_len` bytes
unsafe { heap.as_mut_vec().extend_from_slice(&buf[..*len]) };
heap.push(c);
self.0 = SmolStrBuilderRepr::Heap(heap);
}
}
SmolStrBuilderRepr::Heap(h) => h.push(c),
}
}
pub fn push_str(&mut self, s: &str) {
match &mut self.0 {
SmolStrBuilderRepr::Inline { len, buf } => {
let old_len = *len;
*len += s.len();
// ... rest of the implementation
```
--------------------------------
### SmolStr - Constructors
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/struct.SmolStr
Provides methods for creating SmolStr instances with different allocation strategies.
```APIDOC
## impl SmolStr
### `new_inline(text: &str) -> SmolStr`
#### Description
Constructs an inline variant of `SmolStr`. This never allocates.
#### Parameters
* `text` (*str*) - The string slice to construct the `SmolStr` from.
#### Panics
Panics if `text.len() > 23`.
### `new_static(text: &'static str) -> SmolStr`
#### Description
Constructs a `SmolStr` from a statically allocated string. This never allocates.
#### Parameters
* `text` (*&'static str*) - The static string slice to construct the `SmolStr` from.
### `new(text: impl AsRef) -> SmolStr`
#### Description
Constructs a `SmolStr` from a `str`, heap-allocating if necessary.
#### Parameters
* `text` (*impl AsRef*) - The string slice or type that can be converted to a string slice.
```
--------------------------------
### get
Source: https://docs.rs/smol_str/0.3.2/smol_str/struct.SmolStr
Returns a subslice of a string. This is the non-panicking alternative to indexing the string, returning None if the index operation would panic.
```APIDOC
## get
### Description
Returns a subslice of a string. This is the non-panicking alternative to indexing the string, returning None if the index operation would panic.
### Method
N/A
### Endpoint
get(i: I)
### Parameters
#### Path Parameters
- **i** (SliceIndex) - Required - Index of the subslice.
### Request Example
N/A
### Response
#### Success Response (200)
- **Option<&str>** - The subslice or None.
### Response Example
N/A
```
--------------------------------
### Match Indices API
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/struct.SmolStr
Provides an iterator over the disjoint matches of a pattern within a string slice, returning the starting index of each match.
```APIDOC
## GET /string/match_indices
### Description
Returns an iterator over the disjoint matches of a pattern within this string slice as well as the index that the match starts at. For matches of `pat` within `self` that overlap, only the indices corresponding to the first match are returned.
The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches.
### Method
GET
### Endpoint
`/string/match_indices`
#### Query Parameters
- **pat** (Pattern) - Required - The pattern to search for within the string.
### Response
#### Success Response (200)
- **MatchIndices** (Iterator) - An iterator yielding tuples of (index, matched_substring).
#### Response Example
```json
{
"matches": [
{"index": 0, "match": "abc"},
{"index": 6, "match": "abc"},
{"index": 12, "match": "abc"}
]
}
```
```
--------------------------------
### get()
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/smol_str/struct.SmolStr
Returns a subslice of str. This is the non-panicking alternative to indexing the str. Returns None whenever equivalent indexing operation would panic.
```APIDOC
## get()
### Description
Returns a subslice of `str`. This is the non-panicking alternative to indexing the `str`. Returns `None` whenever equivalent indexing operation would panic.
### Method
`pub fn get(&self, i: I) -> Option<&>::Output>`
### Endpoint
N/A
### Parameters
N/A
### Request Example
N/A
### Response
N/A
```
--------------------------------
### SmolStr Blanket Implementations
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/smol_str/struct.SmolStr
Documentation for blanket implementations provided for SmolStr, covering traits like Any, Borrow, CloneToUninit, From, Into, Receiver, ToOwned, ToSmolStr, ToString, TryFrom, and TryInto.
```APIDOC
## SmolStr Blanket Implementations
This section covers the blanket implementations for SmolStr, providing access to various standard Rust traits.
### `impl Any for T`
#### `fn type_id(&self) -> TypeId`
Gets the `TypeId` of `self`.
### `impl Borrow for T`
#### `fn borrow(&self) -> &T`
Immutably borrows from an owned value.
### `impl BorrowMut for T`
#### `fn borrow_mut(&mut self) -> &mut T`
Mutably borrows from an owned value.
### `impl CloneToUninit for T`
#### `unsafe fn clone_to_uninit(&self, dest: *mut u8)`
Performs copy-assignment from `self` to `dest`.
### `impl From for T`
#### `fn from(t: T) -> T`
Returns the argument unchanged.
### `impl Into for T`
#### `fn into(self) -> U`
Calls `U::from(self)`.
### `impl Receiver for P`
#### `type Target = T`
The target type on which the method may be called.
### `impl ToOwned for T`
#### `fn to_owned(&self) -> T`
Creates owned data from borrowed data, usually by cloning.
#### `fn clone_into(&self, target: &mut T)`
Uses borrowed data to replace owned data, usually by cloning.
### `impl ToSmolStr for T`
#### `fn to_smolstr(&self) -> SmolStr`
Converts the value to a `SmolStr`.
### `impl ToString for T`
#### `fn to_string(&self) -> String`
Converts the given value to a `String`.
### `impl TryFrom for T`
#### `type Error = Infallible`
The type returned in the event of a conversion error.
#### `fn try_from(value: U) -> Result>::Error>`
Performs the conversion.
### `impl TryInto for T`
#### `type Error = >::Error`
The type returned in the event of a conversion error.
#### `fn try_into(self) -> Result>::Error>`
Performs the conversion.
### `impl DeserializeOwned for T`
This trait is implemented for types that can be deserialized from borrowed data.
```
--------------------------------
### trim_start
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/smol_str/struct.SmolStr
Returns a string slice with leading whitespace removed, according to Unicode `White_Space` definition. Considers text directionality.
```APIDOC
## GET /string/trim_start
### Description
Returns a string slice with leading whitespace removed. Whitespace is defined according to the Unicode Derived Core Property `White_Space`, which includes newlines. This method considers text directionality for determining the 'start'.
### Method
GET
### Endpoint
`/string/trim_start`
### Parameters
#### Query Parameters
- **string** (string) - Required - The input string slice.
### Request Example
```json
{
"string": "\n Hello\tworld\t\n"
}
```
### Response
#### Success Response (200)
- **trimmed_string** (string) - The string slice with leading whitespace removed.
#### Response Example
```json
{
"trimmed_string": "Hello\tworld\t\n"
}
```
```
--------------------------------
### get_unchecked - Get Subslice Unsafely
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/struct.SmolStr
Returns an unchecked subslice of `str`. Callers must ensure indices are valid and on UTF-8 sequence boundaries.
```APIDOC
## pub unsafe fn get_unchecked(&self, i: I) -> &>::Output>
### Description
Returns an unchecked subslice of `str`. This is the unchecked alternative to indexing the `str`.
### Safety
Callers of this function are responsible that these preconditions are satisfied:
* The starting index must not exceed the ending index;
* Indexes must be within bounds of the original slice;
* Indexes must lie on UTF-8 sequence boundaries.
Failing that, the returned string slice may reference invalid memory or violate the invariants communicated by the `str` type.
### Method
GET
### Endpoint
N/A (Method on `str` type)
### Parameters
* `i` (Range or `usize`): The range or index to slice.
### Request Example
```rust
let v = "🗻∈🌏";
unsafe {
assert_eq!("🗻", v.get_unchecked(0..4));
assert_eq!("∈", v.get_unchecked(4..7));
assert_eq!("🌏", v.get_unchecked(7..11));
}
```
### Response
#### Success Response (N/A)
Returns the unchecked subslice `&str`.
#### Response Example
```rust
// For v.get_unchecked(0..4) on "🗻∈🌏"
"🗻"
```
```
--------------------------------
### SmolStr::len - Get Byte Length
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/src/smol_str/lib.rs
Returns the length of the `SmolStr` in bytes. This is a performance-oriented method for checking the size of the string data.
```rust
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
extern crate alloc;
use alloc::{borrow::Cow, boxed::Box, string::String, sync::Arc};
use core::{
borrow::Borrow,
cmp::{self, Ordering},
convert::Infallible,
fmt,
hash,
iter,
mem,
ops,
str::FromStr,
};
pub struct SmolStr(Repr);
impl SmolStr {
/// Returns the length of `self` in bytes.
#[inline(always)]
pub fn len(&self) -> usize {
self.0.len()
}
}
```
--------------------------------
### SmolStr Ordering Comparison (PartialOrd)
Source: https://docs.rs/smol_str/0.3.2/smol_str/struct.SmolStr
This section covers the `PartialOrd` implementation for `SmolStr`, enabling ordered comparisons using operators like `<`, `<=`, `>`, and `>=`. The `partial_cmp` method provides a comprehensive ordering, returning an `Option` if a comparison is possible. The `lt`, `le`, `gt`, and `ge` methods are convenience functions for specific comparison operations.
```Rust
impl PartialOrd for SmolStr {
fn partial_cmp(&self, other: &SmolStr) -> Option;
fn lt(&self, other: &Rhs) -> bool;
fn le(&self, other: &Rhs) -> bool;
fn gt(&self, other: &Rhs) -> bool;
fn ge(&self, other: &Rhs) -> bool;
}
```
--------------------------------
### trim_start_matches
Source: https://docs.rs/smol_str/0.3.2/x86_64-apple-darwin/smol_str/struct.SmolStr
Returns a string slice with all prefixes that match a pattern repeatedly removed.
```APIDOC
## trim_start_matches
### Description
Returns a string slice with all prefixes that match a pattern repeatedly removed. The pattern can be a `&str`, `char`, a slice of `char`s, or a function or closure that determines if a character matches.
### Method
GET (implicitly, as it's a method on a string slice)
### Endpoint
N/A (this is a string method)
### Parameters
- **pat** (Pattern) - Required - The pattern to match for trimming from the start.
### Request Example
```rust
assert_eq!("11foo1bar11".trim_start_matches('1'), "foo1bar11");
assert_eq!("123foo1bar123".trim_start_matches(char::is_numeric), "foo1bar123");
let x: &[_] = &['1', '2'];
assert_eq!("12foo1bar12".trim_start_matches(x), "foo1bar12");
```
### Response
#### Success Response (200)
- **&str**: The string slice with matching prefixes removed.
#### Response Example
```
"foo1bar11"
```
```
--------------------------------
### Deref to str: Checking if String is Empty Example
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/struct.SmolStr
Shows how to use the is_empty method on a string slice, which can be obtained from SmolStr via Deref coercion.
```Rust
let s = "";
assert!(s.is_empty());
let s = "not empty";
assert!(!s.is_empty());
```
--------------------------------
### Get TypeId of a type in Rust (Generic)
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/struct.SmolStrBuilder
Demonstrates the `type_id` method, part of the `Any` trait, which returns the `TypeId` of a type. This is a generic implementation applicable to any type.
```Rust
fn type_id(&self) -> TypeId
```
--------------------------------
### Find using Closures and Point-Free Style in Rust
Source: https://docs.rs/smol_str/0.3.2/x86_64-pc-windows-msvc/smol_str/struct.SmolStr
Illustrates advanced pattern matching with the `find` method in Rust using closures and point-free style. This allows for dynamic pattern matching based on character properties like whitespace or case. It returns the byte index of the first match or `None`.
```rust
let s = "Löwe 老虎 Léopard";
assert_eq!(s.find(char::is_whitespace), Some(5));
assert_eq!(s.find(char::is_lowercase), Some(1));
assert_eq!(s.find(|c: char| c.is_whitespace() || c.is_lowercase()), Some(1));
assert_eq!(s.find(|c: char| (c < 'o') && (c > 'a')), Some(4));
```
--------------------------------
### SmolStr Comparison (PartialEq)
Source: https://docs.rs/smol_str/0.3.2/i686-unknown-linux-gnu/struct.SmolStr
This section covers the equality and inequality comparison methods for SmolStr against String, str, and other SmolStr instances.
```APIDOC
## SmolStr Comparison (PartialEq)
### Description
These methods allow for checking equality and inequality between `SmolStr` and other string types.
### Methods
#### `eq(&self, other: &String) -> bool`
Tests for equality between `self` and `other` String values. Used by the `==` operator.
#### `ne(&self, other: &String) -> bool`
Tests for inequality between `self` and `other` String values. Used by the `!=` operator.
#### `eq(&self, other: &str) -> bool`
Tests for equality between `self` and `other` str values. Used by the `==` operator.
#### `ne(&self, other: &str) -> bool`
Tests for inequality between `self` and `other` str values. Used by the `!=` operator.
#### `eq(&self, other: &SmolStr) -> bool`
Tests for equality between `self` and `other` SmolStr values. Used by the `==` operator.
#### `ne(&self, other: &SmolStr) -> bool`
Tests for inequality between `self` and `other` SmolStr values. Used by the `!=` operator.
```
--------------------------------
### Repr Methods
Source: https://docs.rs/smol_str/0.3.2/i686-pc-windows-msvc/src/smol_str/lib.rs
Methods associated with the Repr enum for handling string data, including checking for emptiness, getting length, and converting to a string slice.
```APIDOC
## Repr Methods
### Description
Methods for the `Repr` enum to manage string data efficiently. This includes checking if the string is empty, determining its length, and providing access to the underlying string slice.
### Methods
- `len(&self) -> usize`:
Returns the length of the string represented by `Repr`.
- `is_empty(&self) -> bool`:
Checks if the string represented by `Repr` is empty.
- `as_str(&self) -> &str`:
Returns a string slice (`&str`) view of the string data.
- `ptr_eq(&self, other: &Self) -> bool`:
Compares two `Repr` instances for pointer equality.
```