1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//! Compile-time plugins: registered with [`export_plugin!`](crate::export_plugin)
//! and collected at link time.
//!
//! A plugin crate writes `rich_plugin_api::export_plugin!(MyPlugin);` once.
//! Every such plugin in the final binary is listed by [`linked_plugins`], and
//! a host (`rs-rich-ext`'s `ExtensionRegistry::with_linked_plugins`) adds them
//! in a fixed order: sorted by plugin id, with a duplicate id an error.
//!
//! Collection uses [`inventory`], which needs no proc macro and works on every
//! platform `rich` supports. One caveat, shared by every link-time scheme: a
//! crate the binary depends on but never names may be dropped by the linker.
//! Name it once (`use my_plugin as _;`) to keep its plugins.
use cratePlugin;
/// One plugin submitted with [`export_plugin!`](crate::export_plugin).
collect!;
/// Every plugin exported with [`export_plugin!`](crate::export_plugin) in this
/// binary, in no particular order (a host sorts them by id).
/// Register a plugin for link-time collection.
///
/// The argument is an expression that makes the plugin, evaluated each time
/// a host asks for it. It must not capture anything:
///
/// ```
/// use rich_plugin_api::{Plugin, PluginError, PluginMetadata, PluginRegistrar};
///
/// struct Hello;
/// impl Plugin for Hello {
/// fn metadata(&self) -> PluginMetadata {
/// PluginMetadata::new("hello", "Hello", "1.0.0")
/// }
/// fn register(&self, _: &mut dyn PluginRegistrar) -> Result<(), PluginError> {
/// Ok(())
/// }
/// }
///
/// rich_plugin_api::export_plugin!(Hello);
///
/// # fn main() {
/// assert!(rich_plugin_api::linked_plugins().any(|p| p.plugin().metadata().id == "hello"));
/// # }
/// ```