Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-10 Thread Philippe Delrieu
I trying to do some polymorphism with trait and object and I have some problems. At the beginning I want to store different types of object that implement the same trait (Base) in a Vec. To do this I use the enum pattern. If the enum contains only struct, I manage to iter the Vec for the

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-09 Thread Philippe Delrieu
I find a solution by removing the ~ to Base trait. The code //(First and Second think as defined earlier) enum BaseImpl{ FirstThinkImpl(FirstThink), SecondThinkImpl(SecondThink), } struct Container{ nodeList: Vec~BaseImpl, } impl'a Container{ fn iter_base('a

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-07 Thread Rodrigo Rivas
On Sun, Apr 6, 2014 at 7:50 PM, Philippe Delrieu philippe.delr...@free.fr wrote: I need some more help. The impl Iteratormut ~Base for Container declaration generate the error: error: missing lifetime specifier So I had it but I can't manage to return the next value with the specified life

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-07 Thread Philippe Delrieu
Thanks for your help. I'll test ASAP. I use the counter mutable var to have a simple implantation of the iterator to make the code works. Thank for you're example to show a better way. I was thinking of a similar way but I would like to avoid the specific struct with perhaps use a recursive

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-07 Thread Philippe Delrieu
I try to implement the iterator like that: struct BaseItems'a { iter : Items'a, ~BaseImpl } impl'a Iterator'a ~Base for BaseItems'a { fn next(mut self) - Option'a ~Base{ match self.iter.next() { Some(ref baseimpl) = { Some('a match

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-06 Thread Philippe Delrieu
I need some more help. The impl Iteratormut ~Base for Container declaration generate the error: error: missing lifetime specifier So I had it but I can't manage to return the next value with the specified life time. The code : impl'a Iterator'a mut ~Base for Container { /// Advance the

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-05 Thread Rodrigo Rivas
On Fri, Apr 4, 2014 at 10:41 PM, Philippe Delrieu philippe.delr...@free.fr wrote: Hello, I've some problem to find a solution for something I want to do with a vector of enum. This is an example of what I want to do: trait Base{ fn set_something(mut self); } struct FirstThink;

Re: [rust-dev] Some help needed in Vector of enum conversion

2014-04-05 Thread Philippe Delrieu
Very good idea. The vector don't have to be modified so it'll work. Thank you for the advice. I make a try an I'll post the result. Philippe Le 05/04/2014 21:59, Rodrigo Rivas a écrit : On Fri, Apr 4, 2014 at 10:41 PM, Philippe Delrieu philippe.delr...@free.fr wrote: Hello, I've some

[rust-dev] Some help needed in Vector of enum conversion

2014-04-04 Thread Philippe Delrieu
Hello, I've some problem to find a solution for something I want to do with a vector of enum. This is an example of what I want to do: trait Base{ fn set_something(mut self); } struct FirstThink; impl Base for FirstThink{ fn set_something(mut self){} } struct SecondThink;