I have start 6 month ago with Rust. Most of my time i work with .Net (VisualBasic and C#) to develop customer requests.
I have created my own personal project to learn and understand Rust better. How it works and what is the dynamic of this language.
Yeah and i think i have to much time and i feel boring since corona and the project called "How to create my own languange with Rust" was born.
Yes the easiest project for beginners.
And the finaly answer to your question.
I have a parser module that holds other modules that knows how to handle with the tokens.
For exmaple import_keyword module.
mod import_keyword;
while let Some(token_item) = reader.next(){
import_keyword::check(&token_item);
}
Since i have write this text, i think i have found a other solution and has become a better understanding of my problem
parser.rs
mod import_keyword;
mod other_keyword;
mod one_more_keyword;
trait CheckToken{
fn parse_token(token: &str) -> Result<ImportAst, Error>
}
pub struct Parser;
impl Parser{
pub fn analyze(&mut self){
while let Some(token_item) = reader.next(){
let res = import_keyword::Parser.parse_token(&token_item);
// code -> handle res
// let res = other_keyword::Parser.parse_token(&token_item);
// code -> handle res
// let res = one_more_keyword::Parser.parse_token(&token_item);
// and so on
}
}
}
import_keyword.rs
use crate::parser::CheckToken
pub struct Parser;
impl CheckToken for Parser{
fn parse_token(token: &str) -> Result<ImportAst, Error>{
// code to return Result
}
}
The point is not to have dynamic call, the point is to have a unity call.
And by the way. When i read your solution i have understand, importing a module is not all.
I need to know more details from the module to use it. But i can define the detail by a trait and that is the only point i need to to know about the module.
The rest of the implementation inside the module is internal. The outside dont need to know about it.
At the end of the day i hope i have understand Rust for a better usage and not develop a own language.