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
88
89
90
91
92
93
//! # Qubit SPI
//!
//! Typed service provider infrastructure for Qubit Rust crates.
//!
//! This crate provides the small service-provider layer that many Qubit crates
//! need when a base crate owns a trait and extension crates provide optional
//! implementations. A [`ServiceProvider`] supplies stable names, aliases,
//! runtime availability, priority, and a factory method. A
//! [`ProviderRegistry`] resolves providers by name, by automatic priority, or
//! through an explicit fallback chain.
//!
//! # Examples
//!
//! Register a provider and create a service by name:
//!
//! ```rust
//! use std::fmt::Debug;
//!
//! use qubit_spi::{
//! ProviderCreateError,
//! ProviderDescriptor,
//! ProviderRegistry,
//! ProviderRegistryError,
//! ServiceProvider,
//! ServiceSpec,
//! };
//!
//! trait Greeter: Debug + Send + Sync {
//! fn greet(&self) -> &'static str;
//! }
//!
//! #[derive(Debug)]
//! struct EnglishGreeter;
//!
//! impl Greeter for EnglishGreeter {
//! fn greet(&self) -> &'static str {
//! "hello"
//! }
//! }
//!
//! #[derive(Debug)]
//! struct EnglishProvider;
//!
//! #[derive(Debug)]
//! struct GreeterSpec;
//!
//! impl ServiceSpec for GreeterSpec {
//! type Config = ();
//! type Service = dyn Greeter;
//! }
//!
//! impl ServiceProvider<GreeterSpec> for EnglishProvider {
//! fn descriptor(&self) -> Result<ProviderDescriptor, ProviderRegistryError> {
//! ProviderDescriptor::new("english")?.with_aliases(&["en"])
//! }
//!
//! fn create_box(&self, _config: &()) -> Result<Box<dyn Greeter>, ProviderCreateError> {
//! Ok(Box::new(EnglishGreeter))
//! }
//! }
//!
//! let mut registry = ProviderRegistry::<GreeterSpec>::new();
//! registry
//! .register(EnglishProvider)
//! .expect("provider names should be unique");
//!
//! let greeter = registry
//! .create_box("en", &())
//! .expect("registered provider should create a greeter");
//! assert_eq!("hello", greeter.greet());
//! ```
pub use ProviderAvailability;
pub use ProviderCreateError;
pub use ProviderDescriptor;
pub use ProviderFailure;
pub use ProviderName;
pub use ProviderRegistry;
pub use ProviderRegistryError;
pub use ProviderSelection;
pub use ServiceProvider;
pub use ServiceSpec;