Skip to main content

clack_plugin/
factory.rs

1//! Factory types and associated utilities.
2//!
3//! In CLAP, factories are singleton objects exposed by the plugin library's
4//! [entry point](crate::entry), which can in turn expose various functionalities.
5//!
6//! Each factory type has a standard, unique [identifier](Factory::IDENTIFIERS), which allows hosts
7//! to query plugins for known factory type implementations.
8//!
9//! In Clack, factory implementations are represented by the [`Factory`] trait.
10//!
11//! The main factory type (and, at the time of this writing, the only stable standard one), is the
12//! [`PluginFactory`](plugin::PluginFactoryImpl), which enables hosts to list all the plugin
13//! implementations present in an entry.
14//!
15//! See the [`Entry`](crate::entry::Entry) trait documentation for an example on how to create a
16//! custom entry and plugin factory.
17
18mod error;
19pub mod plugin;
20mod wrapper;
21
22pub use clack_common::factory::*;
23pub use error::FactoryWrapperError;
24pub use wrapper::FactoryWrapper;
25
26/// A types that provides a specific factory implementation.
27///
28/// # Safety
29///
30/// The wrapper returned by the [`wrapper`](Self::wrapper) function *must* wrap a `Raw` implementation
31/// that fully complies to the CLAP specification of the given [`Factory`] type, and must remain
32/// valid for the duration of the `'a` lifetime.
33pub unsafe trait FactoryImplementation<'a>: 'a {
34    /// The [`Factory`] type this is able to provide.
35    type Factory: Factory<'a>;
36    /// The inner factory implementation type in the [`FactoryWrapper`] returned by [`wrapper`](Self::wrapper)
37    type Wrapped;
38
39    /// Returns the [`FactoryWrapper`] instance this type is able to provide.
40    fn wrapper(&self) -> &FactoryWrapper<<Self::Factory as Factory<'a>>::Raw, Self::Wrapped>;
41}