impl Multiplier { fn new()->Multiplier{ Multiplier{product:1} } fn mutiplayer(&mut…
Jump to turn (7)
- 1impl Multiplier { fn new()->Multiplier{ Multiplier{product:1} } fn mutiplayer(&m
- 2fn multiplywithclosure (&mut self, value: i32, f: F) where F: Fn(i32) -> i32, //
- 3Trait 約束 where F: Fn(i32) -> i32, 請多多解釋
- 4let snackbox = Arc::new(Mutex::new(10));如果只有arc 會怎麼樣
- 5Arc 和 Mutex 在學習rust難易度是多少
- 6struct Bag { items:Vec } impl Bag { fn new() ->Bag { Bag{items:Vec::new()} } fn
- 7請問可以再擴展嗎?讓程式變得有趣
- User
impl Multiplier { fn new()->Multiplier{ Multiplier{product:1} } fn mutiplayer(&mut self,value:i32){ self.product *= value; } fn get_value(&self)->i32{ self.product }
請擴展程式,順邊讓我學閉包
- Assistant
好的!我們可以擴展你的 Rust 程式碼,添加一個使用閉包的功能。這個功能將允許我們在 結構中傳遞一個閉包,這個閉包將對每個傳入的值進行處理,然後再進行乘法計算。