I'm writing a game-playing AI in Rust. The strategy module includes a folder with standardized modules that handle specific situations. I want to be able to create a new module anytime I think of a new situation that I would like handled.
I can accomplish this in Node. For example, in an MVC setup, you might have
├── src
├── controllers
├── index.js
└── ...
├── models
├── index.js
└── ...
└── views
├── index.js
└── ...
with a controllers/index.js file containing
////////////////////////////////////////////////////////////////////////////////
// Imports
////////////////////////////////////////////////////////////////////////////////
// Models
const models = require('../models');
// Modules
const fs = require('fs');
const path = require('path');
////////////////////////////////////////////////////////////////////////////////
// Module
////////////////////////////////////////////////////////////////////////////////
const controllers = {};
const basename = path.basename(__filename);
fs.readdirSync(__dirname)
.filter(file => {
return (file.indexOf('.') !== 0) &&
(file !== basename) &&
(file.slice(-3) === '.js');
})
.forEach(file => {
controllers[file.slice(0,-3)] = require(`./${file}`)(models) ;
});
Can I accomplish something similar in Rust?