[Rust] String vs &str ์ •๋ฆฌ

0xDaveยท2022๋…„ 7์›” 20์ผ
0

Rust

๋ชฉ๋ก ๋ณด๊ธฐ
13/16
post-custom-banner

๐Ÿšจ ๊ณต๋ถ€ํ•œ์ง€ ์–ผ๋งˆ ๋˜์ง€ ์•Š์•˜๊ธฐ ๋•Œ๋ฌธ์— ํ‹€๋ฆฐ ๋‚ด์šฉ์ด ์žˆ์„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.


์š”์•ฝ



String


String ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ๋งŒ๋“ค๋ฉด String์ด๋ผ๋Š” ํƒ€์ž… ๊ทธ ์ž์ฒด๋Š” Stack์— ์ €์žฅ๋˜๊ณ , String ํƒ€์ž…์ด ๊ฐ€๋ฆฌํ‚ค๋Š” ์ฃผ์†Œ๋ฅผ ๊ฐ€๋ฉด Heap ์— ์‹ค์ œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜์–ด ์žˆ๋‹ค.

&String


&String ์€ ๋‹จ์ˆœํžˆ String์˜ ์ฐธ์กฐ ํ˜•ํƒœ๋กœ Stack ์— ์ €์žฅ๋˜๋ฉฐ String์˜ ์ฃผ์†Œ๊ฐ’์„ ๊ฐ€์ง„๋‹ค.


์ถœ์ฒ˜ ๋ฐ ์ฐธ๊ณ  ์ž๋ฃŒ


  1. https://youtu.be/BKvHxhlftsU
  2. https://youtu.be/g-HG0b7iWTI
  3. https://stackoverflow.com/questions/24158114/what-are-the-differences-between-rusts-string-and-str
profile
Just BUIDL :)
post-custom-banner

1๊ฐœ์˜ ๋Œ“๊ธ€

comment-user-thumbnail
2023๋…„ 1์›” 15์ผ

์•ˆ๋…•ํ•˜์„ธ์š” ~ ๊ธ€ ์ž˜ ๋ดค์Šต๋‹ˆ๋‹ค
๋‹ค๋ฆ„์ด ์•„๋‹ˆ๋ผ, ์ถ”๊ฐ€๋˜์—ˆ์œผ๋ฉด ์ข‹์„ ๊ฑฐ ๊ฐ™์•„์„œ ๋Œ“๊ธ€ ๋‚จ๊น๋‹ˆ๋‹ค.
&'static str์˜ ๊ฒฝ์šฐ code์˜์—ญ์— ์กด์žฌํ•ฉ๋‹ˆ๋‹ค.

๋‹ต๊ธ€ ๋‹ฌ๊ธฐ