Skip to main content

trait_kit/core/
builder.rs

1// Copyright © 2026 Kirky.X. All rights reserved.
2
3//! Builder traits for module initialization.
4
5use super::module::Module;
6
7/// The standard builder trait for module initialization.
8///
9/// All modules must have a builder that implements this trait.
10/// The `build` method is the only required method and returns
11/// the module's capability or an error.
12pub trait ModuleBuilder<M: Module> {
13    /// Build the module's capability.
14    ///
15    /// Returns `Ok(M::Capability)` on success, or `Err(M::Error)` on failure.
16    fn build(self) -> Result<M::Capability, M::Error>;
17}
18
19/// Trait for builders that accept configuration.
20///
21/// Modules with `Config != NoConfig` should have builders that implement this trait.
22pub trait WithConfig<M: Module> {
23    /// Inject configuration into the builder.
24    ///
25    /// Returns `Self` for method chaining.
26    fn config(self, config: M::Config) -> Self;
27}
28
29/// Trait for builders that accept dependencies.
30///
31/// Modules with `Requirements != NoRequirements` should have builders that implement this trait.
32pub trait WithRequirements<M: Module> {
33    /// Inject requirements (dependencies) into the builder.
34    ///
35    /// Returns `Self` for method chaining.
36    fn requirements(self, requirements: M::Requirements) -> Self;
37}