nargo_transformer/passes/
example_plugin.rs1use nargo_types::Result;
2
3pub struct ExamplePlugin {
5 config: Option<super::super::PluginConfig>,
7}
8
9impl ExamplePlugin {
10 pub fn new() -> Self {
12 Self { config: None }
13 }
14}
15
16impl super::super::Plugin for ExamplePlugin {
17 fn name(&self) -> String {
19 "example-plugin".to_string()
20 }
21
22 fn description(&self) -> String {
24 "示例插件,用于演示插件系统的使用".to_string()
25 }
26
27 fn init(&mut self, config: &super::super::PluginConfig) -> Result<()> {
29 self.config = Some(config.clone());
30 println!("ExamplePlugin initialized with config: {:?}", config);
31 Ok(())
32 }
33
34 fn run(&mut self, _ir: &mut super::super::IRModule, lifecycle: super::super::PluginLifecycle) -> Result<()> {
36 println!("ExamplePlugin running at lifecycle: {:?}", lifecycle);
37
38 match lifecycle {
40 super::super::PluginLifecycle::Init => {
41 println!("ExamplePlugin: Init phase");
42 }
43 super::super::PluginLifecycle::PreTransform => {
44 println!("ExamplePlugin: PreTransform phase");
45 }
46 super::super::PluginLifecycle::Transform => {
47 println!("ExamplePlugin: Transform phase");
48 }
49 super::super::PluginLifecycle::PostTransform => {
50 println!("ExamplePlugin: PostTransform phase");
51 }
52 super::super::PluginLifecycle::Cleanup => {
53 println!("ExamplePlugin: Cleanup phase");
54 }
55 }
56
57 Ok(())
58 }
59
60 fn cleanup(&mut self) -> Result<()> {
62 println!("ExamplePlugin cleaned up");
63 Ok(())
64 }
65}