Clone
๊ฐ์ ๋ณต์ฌํด์ผ ํ๋ ๊ฒฝ์ฐ๋ ์์ต๋๋ค. Clone
ํธ๋ ์์ ์ฌ์ฉํ๋ฉด ๋ฉ๋๋ค.
#[derive(Default)] struct Backends { hostnames: Vec<String>, weights: Vec<f64>, } impl Backends { fn set_hostnames(&mut self, hostnames: &Vec<String>) { self.hostnames = hostnames.clone(); self.weights = hostnames.iter().map(|_| 1.0).collect(); } }
This slide should take about 2 minutes.
Clone
์ ๊ฐ๋
์ ํ ํ ๋น์ด ๋ฐ์ํ๋ ์์น๋ฅผ ์ฝ๊ฒ ์์๋ด๋ ๊ฒ์
๋๋ค. .clone()
๋ฐ Vec::new
๋๋ Box::new
์ ๊ฐ์ ๋ค๋ฅธ ์ฝ๋๋ ์ฐพ์๋ด
๋๋ค.
๋น๋ฆผ ๊ฒ์ฌ๊ธฐ๋ก ๋ฌธ์ ํด๊ฒฐ ๋ฐฉ๋ฒ์ โํด๋ก โํ๊ณ ๋์ค์ ๋ค์ ๋ฐฉ๋ฌธํ์ฌ ํด๋น ํด๋ก ์ ์ต์ ํํ๋ ค๊ณ ์๋ํ๋ ๊ฒฝ์ฐ๊ฐ ๋ง์ต๋๋ค.