intercom 0.4.0

Utilities for writing COM visible Rust components.
Documentation

Tools to define Rust components compatible with the COM protocol.

Intercom provides attributes to automatically derive extern compatible functions for Rust methods. These functions are compatible with COM binary interface standard, which allows them to be used from any language that supports COM.

Examples

A basic example of a calculator type exposed as a COM object.

use intercom::{com_library, com_class, com_interface, ComResult};

// Define COM classes to expose from this library.
com_library!(class Calculator);

// Define the COM class and the interfaces it implements.
#[com_class(Self)]
#[derive(Default)]
struct Calculator;

// Define the implementation for the class. The COM interface is defined
// implicitly by the `impl`.
#[com_interface]
impl Calculator {
    fn add(&self, a: i32, b: i32) -> ComResult<i32> { Ok(a + b) }
    fn sub(&self, a: i32, b: i32) -> ComResult<i32> { Ok(a - b) }
}
# // Without 'main()' doctests wraps the whole thing into a function,
# // which would end up expanding com_library!(..) into a statement.
# // And proc macros into statements are not allowed.
# //
# // In addition to that, if we just have `fn main()` followed by open
# // brace _anywhere_ in this doctest (yes, including these comments),
# // clippy would discover that and yell at us for "needless doctest main".
# // Allowing that with a specific #[allow(..)] attribute is impossible
# // since this is crate-level documentation.
# //
# // Fortunately we can hide this from clippy by specifying the (empty)
# // return type.
# fn main() -> () { }

The above library can be used for example from C# in the following manner.

void Main()
{
    var calculator = new CalculatorLib.Calculator();
    Console.WriteLine( calculator.Add( 1, 2 ) );
}