4 releases (breaking)

0.4.0 Jul 2, 2022
0.3.0 Oct 1, 2019
0.2.0 Dec 10, 2017
0.1.0 Nov 5, 2017

#2093 in Rust patterns

40 downloads per month

MIT license

195KB
5K SLoC

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) }
}

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 ) );
}

Dependencies

~2.4–3.5MB
~71K SLoC