Struct ffi_support::handle_map::Handle [−][src]
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
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 Clone for Handle
[src]
impl Copy for Handle
[src]
impl Debug for Handle
[src]
impl From<u64> for Handle
[src]
impl<T> Index<Handle> for HandleMap<T>
[src]
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 PartialEq<Handle> for Handle
[src]
impl StructuralPartialEq for Handle
[src]
Auto Trait Implementations
impl RefUnwindSafe for Handle
impl Send for Handle
impl Sync for Handle
impl Unpin for Handle
impl UnwindSafe for Handle
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,