- Rust Programming By Example
- Guillaume Gomez Antoni Boucher
- 87字
- 2021-07-02 19:12:57
Clone types
An alternative to using references is to clone values. By cloning a value, we don't move it. To be able to clone a point, we can add derive to it:
#[derive(Clone, Debug)] struct Point { x: i32, y: i32, }
We can now call the clone() method to avoid moving our p1 point:
fn print_point(point: Point) { println!("x: {}, y: {}", point.x, point.y); } let p1 = Point { x: 1, y: 2 }; let p2 = p1.clone(); print_point(p1.clone()); println!("{}", p1.x);
推薦閱讀
- 專業(yè)圖書館發(fā)展之道
- 北大中文系第一課
- 全民閱讀組織活動(dòng)讀本
- 公共圖書館動(dòng)漫服務(wù)研究
- 地方檔案與文獻(xiàn)研究(第1輯)
- 中國古代戲曲目錄研究
- 新時(shí)代檔案工作新思維
- 圖書館知識(shí)整合與知識(shí)服務(wù)研究:以西部社會(huì)科學(xué)院圖書館為例
- 國際集郵聯(lián)合會(huì)(FIP)集郵展覽評(píng)審規(guī)則
- 圖書館合理分享著作權(quán)利益訴求研究
- 圖書館學(xué)散論:科學(xué)網(wǎng)圖謀博客精粹
- 檔案與少數(shù)民族記憶
- 高校圖書館學(xué)科服務(wù)研究
- 專利計(jì)量與專利合作
- 中國富布賴特學(xué)友會(huì)(籌)論文集(2013)