Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct Base {
- name: String,
- }
- pub enum Fish {
- FishA(Base),
- FishB(Base),
- }
- impl FIsh {
- pub fn foo(&self) -> () {
- match *self {
- Fish::FishA(Base {ref name}) => self.fooA(),
- Fish::FishB(Base {ref nom}) => self.fooB(),
- }
- }
- fn fooA(&self) -> () {
- println!("fooA !");
- }
- fn fooB(&self) -> () {
- println!("fooB !");
- }
- }
- fn main() {
- let v = vec![
- Fish::FishA(Base { name: "John".to_owned() }),
- Fish::FishB(Base { name: "Jean".to_owned() }),
- ];
- for x in v {
- x.foo();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement