Struct ffi_support::handle_map::Handle[][src]

pub struct Handle { /* fields omitted */ }
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 Handles).

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

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.

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.

Returns whether or not v makes a bit pattern that could represent an encoded Handle.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

This type must be: Read more

Return an ‘empty’ value. This is what’s passed back to C in the case of an error, so it doesn’t actually need to be “empty”, so much as “ignorable”. Note that this is also used when an empty Option<T> is returned. Read more

Convert ourselves into a value we can pass back to C with confidence.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.