+---------+ +---------+
| | | |
| APP +-----------> | API |
| | | |
+---------+ +----+----+
^
|
|
|
+----+----+
| |
| LIB |
| |
+---------+
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");
}
}
}
/**
* myapi/include/Printer.h
*/
namespace api {
class Printer {
public:
void print();
};
}
/**
* mylib/src/MyPrinter.cpp
*/
namespace api {
void Printer::print() {
cout << "hello" << endl;
}
}