Target Generation
Every TGA—that includes 6Gen, SixForest, 6GAN, and your own additions—implements the trait quartet defined in tga/src/lib.rs:
TgaInfosupplies staticNAMEandDESCRIPTIONconstants so the CLI and docs can describe the algorithm.TgaGeneratoris the runtime iterator that producesAddressvalues; it must beClone + Sendand expose agenerate()method.TgaModellinks training output to its generator viatype Generatorand thebuild(seed)constructor. Models must beSerialize + Deserialize + Displayso they can be persisted and inspected.TGAis the Clap-friendly configuration (clap::Args + Serialize + Deserialize). Itstrainmethod consumes an iterator ofAddressseeds and returns aTgaModel.
#[derive(clap::Args, Clone, Serialize, Deserialize)]
pub struct FooGen {
#[arg(long, default_value_t = 16)]
pub window: usize,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct FooModel {
patterns: Vec<AddressPattern>,
}
impl TGA for FooGen {
type Model = FooModel;
async fn train<T: IntoIterator<Item = Address>>(
&self,
seeds: T,
) -> Result<Self::Model, String> {
let patterns = mine_patterns(seeds, self.window)?;
Ok(FooModel { patterns })
}
}
impl TgaModel for FooModel {
type Generator = FooGenerator;
fn build(self, seed: usize) -> FooGenerator {
FooGenerator::new(self, seed)
}
}Registering the plugin
- Add your module to
tga/src/lib.rs, re-export the config/model types, and extendModelEnum/ModelEnumIterator/TgaEnumwith new variants. Each match arm must forward to your training and generation logic. - Update
pyrmap/src/lib.rsso the Python bindings can construct the new config class and map JSON configs onto your type (see the existingPySixGenConfigimplementation for reference). - If you want the documentation to discover the algorithm automatically, add a page under
site/content/docs/target-generation/and reference it from the sidebar.
Best practices
- Keep training asynchronous but CPU-bound: the
trainmethod runs inside a Tokio runtime, so expensive CPU work should usetokio::task::spawn_blockingor Rayon where appropriate. - Implement
Displayfor your model to surface metrics in CLI output (rmap trainwrites the string to stdout). - Store enough metadata in the model to reproduce behaviour across releases; the CLI serializes models with
bincode, so backwards-compatible versions should prefer additive changes.