]> git.lizzy.rs Git - rust.git/blob - src/librustdoc/plugins.rs
Auto merge of #52211 - bjorn3:misc_rustdoc_changes, r=QuietMisdreavus
[rust.git] / src / librustdoc / plugins.rs
1 // Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 #![allow(deprecated)]
12
13 use clean;
14
15 pub type PluginResult = clean::Crate;
16 pub type PluginCallback = fn (clean::Crate) -> PluginResult;
17
18 /// Manages loading and running of plugins
19 pub struct PluginManager {
20     callbacks: Vec<PluginCallback> ,
21 }
22
23 impl PluginManager {
24     /// Create a new plugin manager
25     pub fn new() -> PluginManager {
26         PluginManager {
27             callbacks: Vec::new(),
28         }
29     }
30
31     /// Load a normal Rust function as a plugin.
32     ///
33     /// This is to run passes over the cleaned crate. Plugins run this way
34     /// correspond to the A-aux tag on Github.
35     pub fn add_plugin(&mut self, plugin: PluginCallback) {
36         self.callbacks.push(plugin);
37     }
38     /// Run all the loaded plugins over the crate, returning their results
39     pub fn run_plugins(&self, mut krate: clean::Crate) -> clean::Crate {
40         for &callback in &self.callbacks {
41             krate = callback(krate);
42         }
43         krate
44     }
45 }