[−][src]Struct ffi_support::handle_map::Handle
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.
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
fn ffi_default() -> u64
[src]
fn into_ffi_value(self) -> u64
[src]
impl Clone for Handle
[src]
fn clone(&self) -> 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 Copy for Handle
[src]
impl PartialEq<Handle> for Handle
[src]
impl Debug for Handle
[src]
impl<T> Index<Handle> for HandleMap<T>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,