String

String์€ ํž™์— ํ• ๋‹น๋œ ํ™•์žฅ๊ฐ€๋Šฅํ•œ ํ‘œ์ค€ UTF-8 ๋ฌธ์ž์—ด ๋ฒ„ํผ์ž…๋‹ˆ๋‹ค.

String is the standard heap-allocated growable UTF-8 string buffer:

fn main() {
    let mut s1 = String::new();
    s1.push_str("Hello");
    println!("s1: len = {}, capacity = {}", s1.len(), s1.capacity());

    let mut s2 = String::with_capacity(s1.len() + 1);
    s2.push_str(&s1);
    s2.push('!');
    println!("s2: len = {}, capacity = {}", s2.len(), s2.capacity());
}

String์€ Deref<Target = str>์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Š” , String์—์„œ ๋ชจ๋“  str๊ด€๋ จ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœ ํ•  ์ˆ˜ ์žˆ๋‹ค๋Š” ์˜๋ฏธ ์ž…๋‹ˆ๋‹ค.

String implements Deref<Target = str>, which means that you can call all str methods on a String.