# `SmartString` β `std::string::String` parity table
Legend:
- **Match**:
- β
= full correspondence is possible (same semantics are achievable for a stack-or-heap string)
- π« = full correspondence is not possible (or would require exposing representation/unsafe contracts we intentionally avoid)
- **Implemented**:
- β
= exists
- π‘ = partial (some equivalent exists, but semantics/API differ)
- β = not implemented
Notes:
- `SmartString` can promote from stack to heap, so most `String` APIs can have full semantic parity.
- Some APIs are **unsafe / representation-exposing** (`*_raw_parts`, `as_mut_vec`, `from_utf8_unchecked`). They are
technically possible (by forcing heap) but are treated as βout of scopeβ for now; see the βAdditional/alternativeβ
column.
| `as_bytes` | β
| `as_bytes` | `as_ref::<[u8]>()` | β
|
| `as_mut_str` | β
| `as_mut_str` | *(also `DerefMut<Target=str>`)* | β
|
| `as_mut_vec` | β
| β | *(possible by forcing heap: `s.into_heap()` then `String::as_mut_vec` (unsafe))* | β |
| `as_str` | β
| `as_str` | *(also `Deref<Target=str>`)* | β
|
| `capacity` | β
| `capacity` | β | β
|
| `clear` | β
| `clear` | β | β
|
| `drain` | β
| `drain` | *(currently promotes to heap and delegates)* | β
|
| `extend_from_within` | β
| `extend_from_within` | *(safe: extract range + push_str; promotes to heap on overflow)* | β
|
| `from_raw_parts` | π« | β | *(representation-exposing/unsafe; could exist only for heap variant)* | β |
| `from_utf16` | β
| `from_utf16` | β | β
|
| `from_utf16_lossy` | β
| `from_utf16_lossy` | β | β
|
| `from_utf16be` | β
| `from_utf16be` | *(manual UTF-16 BE decode from `&[u8]`; returns `Utf16DecodeError`)* | β
|
| `from_utf16be_lossy` | β
| `from_utf16be_lossy` | *(lossy variant, replaces invalid with U+FFFD)* | β
|
| `from_utf16le` | β
| `from_utf16le` | *(manual UTF-16 LE decode from `&[u8]`)* | β
|
| `from_utf16le_lossy` | β
| `from_utf16le_lossy` | *(lossy variant)* | β
|
| `from_utf8` | β
| `from_utf8` | β | β
|
| `from_utf8_lossy` | β
| `from_utf8_lossy` | β | β
|
| `from_utf8_lossy_owned` | β
| `from_utf8_lossy_owned` | β | β
|
| `from_utf8_unchecked` | β
| β | *(possible by forcing heap and delegating; unsafe API)* | β |
| `insert` | β
| `insert` | `insert_str_truncated` (SmartString-only helper for stack paths) | β
|
| `insert_str` | β
| `insert_str` | `insert_str_truncated`, `try_insert_str_truncated` | β
|
| `into_boxed_str` | β
| `into_boxed_str` | β | β
|
| `into_bytes` | β
| `into_bytes` | `From<SmartString> for Vec<u8>` | β
|
| `into_chars` | β
| `into_chars` | *(custom `IntoChars<N>` with full trait surface; no `IntoIterator` trait until std stabilizes it)* | β
|
| `into_raw_parts` | π« | β | *(representation-exposing/unsafe; could exist only for heap variant)* | β |
| `is_empty` | β
| `is_empty` | β | β
|
| `leak` | β
| `leak` | β | β
|
| `len` | β
| `len` | *(also `Deref<Target=str>`)* | β
|
| `new` | β
| `new` | β | β
|
| `pop` | β
| `pop` | β | β
|
| `push` | β
| `push` | β | β
|
| `push_str` | β
| `push_str` | β | β
|
| `remove` | β
| `remove` | β | β
|
| `remove_matches` | β
| `remove_matches` | *(accepts `&str`; also `remove_matches_char` for `char`)* | β
|
| `replace_first` | β
| `replace_first` | *(accepts `&str`; also `replace_first_char` for `char`; via `replace_range`)* | β
|
| `replace_last` | β
| `replace_last` | *(accepts `&str`; also `replace_last_char` for `char`; via `replace_range`)* | β
|
| `replace_range` | β
| `replace_range` | β | β
|
| `reserve` | β
| `reserve` | β | β
|
| `reserve_exact` | β
| `reserve_exact` | β | β
|
| `retain` | β
| `retain` | β | β
|
| `shrink_to` | β
| `shrink_to` | β | β
|
| `shrink_to_fit` | β
| `shrink_to_fit` | β | β
|
| `split_off` | β
| `split_off` | *(optimized to avoid allocation when tail fits stack)* | β
|
| `truncate` | β
| `truncate` | β | β
|
| `try_reserve` | β
| `try_reserve` | β | β
|
| `try_reserve_exact` | β
| `try_reserve_exact` | β | β
|
| `try_with_capacity` | β
| `try_with_capacity` | β | β
|
| `with_capacity` | β
| `with_capacity` | β | β
|