FrameworkRule

Trait FrameworkRule 

Source
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§

Source

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:

  1. Load modules via graph.modules().await?
  2. Clone and modify modules that need changes
  3. Save modified modules back via graph.add_module(module).await?

The async nature allows the database backend to handle concurrent updates safely.

Source

fn name(&self) -> &'static str

Human-readable name for the rule (used in diagnostics).

Source

fn description(&self) -> &'static str

Description of what patterns this rule matches.

Source

fn clone_box(&self) -> Box<dyn FrameworkRule>

Clone the rule into a boxed trait object.

Required for storing rules in collections.

Provided Methods§

Source

fn is_default(&self) -> bool

Whether this rule should be enabled by default.

Built-in rules return true, custom rules typically return false.

Trait Implementations§

Source§

impl Clone for Box<dyn FrameworkRule>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Implementors§