Can you elaborate? I imagine an SSO String would have an explicit way to turn a &str or whatever into something on the heap. If they really, really care, a user could do this:
struct HeapString(String);
impl HeapString {
fn new(str: &str) -> Self {
let string = String::in_heap(str);
Self(string)
}
fn into_inner(self) -> String { .. }
unsafe fn new_unchecked(str: String) -> Self { .. }
}
impl Deref for HeapString {
type Target = String; // or str or whatever
// ..
}
I imagine that in most branches involving is_heap would predict true anyway…
Sure, I can imagine wanting that. I think Rust tends to treat String a lot more like e.g. Java StringBuffer than std::string anyways. I wonder if it’s possible to measure whether this would even be a notable improvement…