vst3/lib.rs
1//! The `vst3` crate provides Rust bindings for the VST 3 API, generated from the original C++
2//! headers. Abstractions are provided for manipulating COM objects and implementing COM interfaces
3//! from Rust. Beyond that, however, these bindings are unsafe, and no attempt is made to abstract
4//! over the VST 3 API itself.
5//!
6//! # Bindings
7//!
8//! Generated bindings are primarily located in the [`Steinberg`] module. In addition to the COM
9//! interfaces, bindings include struct definitions, type aliases, constants, and enums. The module
10//! structure of the bindings mirrors the namespace structure of the original headers, with minor
11//! differences where necessary (e.g., definitions which are nested inside a C++ type `SomeType`
12//! will be found inside a `SomeType_` module in the generated bindings).
13//!
14//! For each COM interface `IInterface` in the C++ headers, the bindings include a corresponding
15//! Rust type `IInterface`, a virtual table struct `IInterfaceVtbl`, and a trait `IInterfaceTrait`
16//! (excluding `FUnknown`, for which no trait is generated). Each `IInterface` type also implements
17//! the [`Interface`] trait, which holds an associated constant [`Interface::IID`] specifying the
18//! GUID corresponding to that interface.
19//!
20//! # Interacting with COM objects
21//!
22//! The [`ComPtr`] and [`ComRef`] smart pointers are provided for interacting with COM objects.
23//! These types make it safer and more convenient to call methods, cast between interfaces, and
24//! manage reference counts.
25//!
26//! For an overview of how to properly manage ownership and reference counts using [`ComPtr`] and
27//! [`ComRef`], see the [`com-scrape-types` documentation](com_scrape_types#reference-counting).
28//!
29//! # Implementing COM interfaces from Rust
30//!
31//! COM classes can be defined in Rust using the [`Class`] trait and the interface traits generated
32//! from the VST 3 headers, and objects of these classes can be instantiated using the
33//! [`ComWrapper`] smart pointer:
34//!
35//! ```
36//! # use vst3::{*, Steinberg::*};
37//! struct MyClass;
38//!
39//! impl Class for MyClass {
40//! type Interfaces = (IPluginBase,);
41//! }
42//!
43//! impl IPluginBaseTrait for MyClass {
44//! unsafe fn initialize(&self, context: *mut FUnknown) -> tresult {
45//! kResultOk
46//! }
47//!
48//! unsafe fn terminate(&self) -> tresult {
49//! kResultOk
50//! }
51//! }
52//!
53//! let my_obj = ComWrapper::new(MyClass);
54//! let ptr = my_obj.to_com_ptr::<IPluginBase>().unwrap();
55//! ```
56//!
57//! For more detail on implementing COM interfaces from rust, see the
58//! [`com-scrape-types` documentation](com_scrape_types#implementing-com-interfaces-from-rust).
59
60#![allow(non_upper_case_globals)]
61#![allow(non_camel_case_types)]
62#![allow(non_snake_case)]
63
64pub use com_scrape_types;
65pub use com_scrape_types::{Class, ComPtr, ComRef, ComWrapper, Interface};
66
67mod support;
68
69pub use support::uid;
70
71#[rustfmt::skip]
72mod bindings;
73
74pub use bindings::*;