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
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
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
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
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
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
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;
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
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;