pub trait FrameworkRule: Send + Sync {
// Required methods
fn apply<'life0, 'life1, 'async_trait>(
&'life0 self,
graph: &'life1 ModuleGraph,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
fn name(&self) -> &'static str;
fn description(&self) -> &'static str;
fn clone_box(&self) -> Box<dyn FrameworkRule>;
// Provided method
fn is_default(&self) -> bool { ... }
}Expand description
Framework-specific rule for marking exports as used by framework conventions.
Framework rules identify exports that appear unused but are actually consumed by framework magic (React hooks, Next.js data fetching, Vue composables, etc.).
§Example
ⓘ
use fob_graph::graph::{ModuleGraph, FrameworkRule};
use async_trait::async_trait;
struct MyFrameworkRule;
#[async_trait]
impl FrameworkRule for MyFrameworkRule {
async fn apply(&self, graph: &ModuleGraph) -> Result<()> {
let modules = graph.modules().await?;
for module in modules {
let mut updated = module.clone();
let mut changed = false;
for export in updated.exports.iter_mut() {
if export.name.starts_with("action_") {
export.mark_framework_used();
changed = true;
}
}
if changed {
graph.add_module(updated).await?;
}
}
Ok(())
}
fn name(&self) -> &'static str {
"MyFrameworkRule"
}
fn description(&self) -> &'static str {
"Marks exports prefixed with 'action_' as framework-used"
}
}Required Methods§
Sourcefn apply<'life0, 'life1, 'async_trait>(
&'life0 self,
graph: &'life1 ModuleGraph,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn apply<'life0, 'life1, 'async_trait>(
&'life0 self,
graph: &'life1 ModuleGraph,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Apply the rule to the module graph, marking exports as framework-used.
This method receives immutable access to the graph and should:
- Load modules via
graph.modules().await? - Clone and modify modules that need changes
- Save modified modules back via
graph.add_module(module).await?
The async nature allows the database backend to handle concurrent updates safely.
Sourcefn description(&self) -> &'static str
fn description(&self) -> &'static str
Description of what patterns this rule matches.
Sourcefn clone_box(&self) -> Box<dyn FrameworkRule>
fn clone_box(&self) -> Box<dyn FrameworkRule>
Clone the rule into a boxed trait object.
Required for storing rules in collections.
Provided Methods§
Sourcefn is_default(&self) -> bool
fn is_default(&self) -> bool
Whether this rule should be enabled by default.
Built-in rules return true, custom rules typically return false.