I am working with this CXX rust example code
https://github.com/dtolnay/cxx/blob/master/demo/src/main.rs
// Toy implementation of an in-memory blobstore.
//
// In reality the implementation of BlobstoreClient could be a large complex C++
// library.
class BlobstoreClient::impl {
friend BlobstoreClient;
using Blob = struct {
std::string data;
std::set<std::string> tags;
};
std::unordered_map<uint64_t, Blob> blobs;
};
BlobstoreClient::BlobstoreClient() : impl(new class BlobstoreClient::impl) {}
but I've not ever done this before... my current (de)constructors look like
TWSApiClient::TWSApiClient():
m_osSignal(2000)//2-seconds timeout
, m_pClient(new EClientSocket(this, &m_osSignal))
, m_state(ST_CONNECT) // starts at m_state = 0
, m_sleepDeadline(0)
, m_orderId(0)
, m_extraAuth(false) {}
TWSApiClient::~TWSApiClient()
{
if( m_pReader ){
m_pReader.reset();
}
delete m_pClient;
}
When I compiled my Rust code... and try to call a Class function... it's not found.. my guess is I am not implementing this Pointer Implementation style that the CXX code is using.. do I merely move my initiators m_state(ST_CONNECT)
into the curly braces of the first code block ?
is this even required for CXX ?
fn main() {
println!("Starting TWSApiClient connect()");
let client = ffi::new_twsapi_client();
client.connect(4002, 333);
println!("Finished TWSApiClient connect()");
}
error[E0599]: no method named `connect` found for struct `UniquePtr<TWSApiClient>` in the current scope
--> src/main.rs:22:12
|
22 | client.connect(4002, 333);
| ^^^^^^^ method not found in `UniquePtr<TWSApiClient>`
For more information about this error, try `rustc --explain E0599`.
error: could not compile `twsapi_grpc_server` due to previous error
EDIT: The full main.rs
#[cxx::bridge(namespace = "com::ourco")]
mod ffi {
unsafe extern "C++" {
include!("twsapi_grpc_server/include/twsapi-client.h");
include!("twsapi_grpc_server/include/AvailableAlgoParams.h");
include!("twsapi_grpc_server/include/AccountSummaryTags.h");
include!("twsapi_grpc_server/include/Utils.h");
type TWSApiClient;
fn new_twsapi_client() -> UniquePtr<TWSApiClient>;
#[allow(dead_code)]
fn connect(self: Pin<&mut TWSApiClient>, port: i32, client_id: i32) -> bool;
}
}
fn main() {
println!("Starting TWSApiClient connect()");
let _client = ffi::new_twsapi_client();
//_client.connect(4002, 333);
println!("Finished TWSApiClient connect()");
}