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

pub struct Handle { /* fields omitted */ }

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.

Methods

impl Handle[src]

pub fn into_u64(self) -> u64[src]

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.

pub fn from_u64(v: u64) -> Result<Self, HandleError>[src]

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.

pub fn is_valid(v: u64) -> bool[src]

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

Trait Implementations

impl IntoFfi for Handle[src]

type Value = u64

This type must be: Read more

impl Copy for Handle[src]

impl PartialEq<Handle> for Handle[src]

impl Clone for Handle[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl From<u64> for Handle[src]

impl From<Handle> for u64[src]

impl Debug for Handle[src]

impl<T> Index<Handle> for HandleMap<T>[src]

type Output = T

The returned type after indexing.

Auto Trait Implementations

impl Send for Handle

impl Sync for Handle

Blanket Implementations

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> From for T[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]