pub struct Handle { /* private fields */ }
Expand description
A Handle we allow to be returned over the FFI by implementing IntoFfi
.
This type is intentionally not #[repr(C)]
, and getting the data out of the
FFI is done using Handle::from_u64
, or it’s implemetation of From<u64>
.
It consists of, at a minimum:
- A “map id” (used to ensure you’re using it with the correct map)
- a “version” (incremented when the value in the index changes, used to detect multiple frees, use after free, and ABA and ABA)
- and a field indicating which index it goes into.
In practice, it may also contain extra information to help detect other
errors (currently it stores a “magic value” used to detect invalid
Handle
s).
These fields may change but the following guarantees are made about the internal representation:
- This will always be representable in 64 bits.
- The bits, when interpreted as a signed 64 bit integer, will be positive (that is to say, it will actually be representable in 63 bits, since this makes the most significant bit unavailable for the purposes of encoding). This guarantee makes things slightly less dubious when passing things to Java, gives us some extra validation ability, etc.
Implementations§
Source§impl Handle
impl Handle
Sourcepub fn into_u64(self) -> u64
pub fn into_u64(self) -> u64
Convert a Handle
to a u64
. You can also use Into::into
directly.
Most uses of this will be automatic due to our IntoFfi
implementation.
Sourcepub fn from_u64(v: u64) -> Result<Self, HandleError>
pub fn from_u64(v: u64) -> Result<Self, HandleError>
Convert a u64
to a Handle
. Inverse of into_u64
. We also implement
From::from
(which will panic instead of returning Err).
Returns HandleError::InvalidHandle
if the bits cannot
possibly represent a valid handle.
Trait Implementations§
Source§impl IntoFfi for Handle
impl IntoFfi for Handle
Source§fn ffi_default() -> u64
fn ffi_default() -> u64
Option<T>
is returned.