2 releases

new 0.1.2 Jan 17, 2025
0.1.1 Jan 17, 2025

#1717 in Rust patterns

Download history

56 downloads per month

BSD-2-Clause

10KB
115 lines

Rust std::time::Instant in C++

include/rust_time.h contains rust::time::Instant, which is a port of Rust's std::time::Instant with memory-layout compatibility.

No guarantee

No guarantee for compatibility.

Since std::time::Instant and std::time::Duration is not #[repr(C)], use it on your own risk. Data without #[repr(C)] is unbelievably fragile on FFI boundary.

See also


lib.rs:

std::time::{Duration, Instant} bindings assistant.

Warning: No guarantee for safe compatibility. Use it at your own risk. Data without #[repr(C)] is very fragile on the FFI boundary.

Using these union types provides a few benefits.

First, memory layout optimization can be prevented. Since these types are not #[repr(C)], the layout can be freely optimized on the Rust side. Using a union helps the internal CDuration reserve the full size of these types. Second, it provides an error check mechanism for operations outside of Rust.

Still, be aware of the risks. This does not mean it is safe, nor does it mean it cannot be broken by future Rust changes.

Dependencies

~84KB