I have implemented static C++ class in some lib. I would like to use it in Rust code without changing the lib.
But I can't find the way to use. Is it possible?
C++ header.
class Comm {
public:
static Buffer makePacket(uint8_t *data, CommHeaderData header);
static bool fetchData(const uint8_t *rawData, const uint8_t rawDataSize, uint8_t *data, const uint8_t dataSize, CommHeaderData &header);
static uint8_t getPacketSize();
static bool validatePacket(uint8_t *data, uint8_t dataSize);
static Buffer createBuffer(size_t dataSize);
static void freeBuffer(Buffer &buffer);
public:
static const uint8_t zdataSize;
static const uint8_t startPid;
static const uint8_t defaultCap;
static const uint8_t maxPayload;
static const size_t headerSize;
};
And draft of Rust caller interface for it.
mod ffi {
#[cxx_name = "CommHeaderData"]
struct CommHeaderDataBridge {
dataSize: usize,
version: u8,
pid: u16,
capabilities: u8,
}
#[cxx_name = "Buffer"]
struct BufferBridge {
dataPtr: u8,
dataSize: usize,
}
unsafe extern "C++" {
include!("libs/Hen-Lib/proto/Comm.h");
type Comm;
fn fetchData(
rawData: &[u8],
rawDataSize: u8,
data: &mut [u8],
dataSize: u8,
header: &mut CommHeaderDataBridge,
) -> bool;
fn makePacket(data: &[u8], header: CommHeaderDataBridge) -> BufferBridge;
}
}
2 posts - 2 participants
Read full topic
| # | Наименование новости | Тональность | Информативность | Дата публикации |
|---|---|---|---|---|
| 1 | Type erasure and dyn lifetime in a NonNull/Box struct field | 0 | 8.55 | 04-10-2026 |
| 2 | Rust abstractions for kernel sources | 0 | 4.62 | 08-10-2026 |
| 3 | Optimization of inlined functions returning Result? | 0 | 7.36 | 06-10-2026 |
| 4 | Why no Dependent Matrix Type? | 0 | 5.16 | 08-10-2026 |
| 5 | Arena's and alignment | 0 | 7.3 | 04-10-2026 |
| 6 | Why is f32/f64::sqrt not const? | 0 | 22.72 | 06-10-2026 |
| 7 | Strategies for dyn trait objects with optional behavior? | 0 | 7.12 | 06-10-2026 |
| 8 | Does my lockfree stack impl look correct? | 0 | 6.06 | 05-10-2026 |
| 9 | Architecture review of a Hyper/Tower-based web framework (Toxi) | 0 | 15.46 | 06-10-2026 |