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์™€ ๊ฐ™์€ ๋‹ค๋ฅธ ์ฝ”๋“œ๋„ ์ฐพ์•„๋ด…๋‹ˆ๋‹ค.

๋นŒ๋ฆผ ๊ฒ€์‚ฌ๊ธฐ๋กœ ๋ฌธ์ œ ํ•ด๊ฒฐ ๋ฐฉ๋ฒ•์„ โ€™ํด๋ก โ€™ํ•˜๊ณ  ๋‚˜์ค‘์— ๋‹ค์‹œ ๋ฐฉ๋ฌธํ•˜์—ฌ ํ•ด๋‹น ํด๋ก ์„ ์ตœ์ ํ™”ํ•˜๋ ค๊ณ  ์‹œ๋„ํ•˜๋Š” ๊ฒฝ์šฐ๊ฐ€ ๋งŽ์Šต๋‹ˆ๋‹ค.