You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitDraw{fndraw(&self) -> String;}implDrawforu8{fndraw(&self) -> String{format!("u8 {}",*self)}}implDrawforf64{fndraw(&self) -> String{format!("f64 {}",*self)}}fndraw1(components:Vec<Box<dynDraw>>){for c in components.iter(){println!("{}", c.draw());}}fndraw2(components:Vec<&dynDraw>){for c in components.iter(){println!("{}", c.draw());}}fndraw3(components:Vec<implDraw>){for c in components.iter(){println!("{}", c.draw());}}fnmain(){let x = 1.1_f64;let y = 8_u8;draw1(vec![Box::new(x),Box::new(y)]);draw2(vec![&x,&y]);// draw3(vec![x, y]); // don't work}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
章节2.8.3 特征对象
文中给了段代码来说明特征对象,代码如下
但我读到这里的时候其实是比较困惑的,因为这里没有体现为什么需要特征对象,这里只是陈述了如何创建特征对象以及如何接收特征对象,我觉得改为如下的例子的话会更好的说明为什么需要它
Beta Was this translation helpful? Give feedback.
All reactions