Trying to learn Rust by writing a parser, but this error is killing me:
ast.rs(7, 11): this trait cannot be made into an object...
ast.rs(7, 29): ...because it requires `Self: Sized`
ast.rs(16, 5): the trait `ast::ast::Statement` cannot be made into an object
Here's the code:
use crate::token::token;
pub trait Node {
fn token_literal(&mut self) -> String;
}
pub trait Statement: Node + Clone {
fn statement_node(&mut self);
}
pub trait Expression: Node + Clone {
fn expression_node(&mut self);
}
pub struct Program {
pub statements: Vec<Box<dyn Statement>>,
}
And I'd like to know why does it keep complaining me about the Sized trait, I'm using Box to avoid it and lifetimes?
I do not want to use Generics for the Program
struct like
pub struct Program<T: Statement> {
pub statements: Vec<T>
}
because when I return a Program
from a function it complains me about some kind of an error like
"it requires 1 argument but got 0"