String

🤔 refer to Will Crichton

#![allow(unused)]
fn main() {
let s1 = String::from("Hello ");
}
VecRawVecUniqueNonNullvecbufpointer72markerPhantomDatacap6allocGloballen6ptrpointerStrings1Stack

🤔 refer to Swatinem

NameSize of <T>Size of <Option<T>>CloneSSOMutable
String2424O(n)-yes
Arc1616O(1)-no
arcstr88O(1)-no
smol_str2424O(1)23no
kstring (arc)2432O(1)15 / 22no
flexstr2432O(1)22no
compact_str2424O(n)24yes
smartstring2432O(n)23yes

🤔 refer to Matt Davies

graph TD
    subgraph "🦀 Strings"
        &Path --to_path_buf--> PathBuf
        PathBuf --into_os_string--> OsString
        PathBuf --as_path--> &Path
        &Path --as_os_str--> &OsStr
        OsString --into_string?--> String
        OsString --as_os_str--> &OsStr
        &OsStr --to_os_string--> OsString
        &OsStr --to_str?--> &str
        String --as_str--> &str
        CString --as_c_str--> &CStr
        CString --into_string?--> String
        &CStr --to_str?-->&str
        String --as_bytes--> u8["&[u8]"]
        &str --as_bytes--> u8["&[u8]"]
        &CStr --to_bytes--> u8["&[u8]"]
        CString --as_bytes--> u8["&[u8]"]
        &str --as_ptr--> cu8["*const u8"]
    end