Rust for C++

API

+---------+             +---------+
|         |             |         |
|   APP   +-----------> |   API   |
|         |             |         |
+---------+             +----+----+
                             ^     
                             |     
                             |     
                             |     
                        +----+----+
                        |         |
                        |   LIB   |
                        |         |
                        +---------+
Rust
mod api {
    pub trait Printer {
        fn new() -> Self;

        fn print(&self);
    }
}

mod library {
    pub struct MyPrinter;

    impl super::api::Printer for MyPrinter {
        fn new() -> MyPrinter {
            MyPrinter
        }

        fn print(&self) {
            println!("hello");
        }
    }
}

Run

C++
/**
 *    myapi/include/Printer.h
 */
namespace api {

class Printer {
public:
    void print();
};

}

/**
 *    mylib/src/MyPrinter.cpp
 */
namespace api {

void Printer::print() {
    cout << "hello" << endl;
}

}

Run