Trait uniffi::RustBufferFfiConverter
source · [−]pub trait RustBufferFfiConverter: Sized {
type RustType;
fn write(obj: Self::RustType, buf: &mut Vec<u8>);
fn try_read(buf: &mut &[u8]) -> Result<Self::RustType>;
}
Expand description
A helper trait to implement lowering/lifting using a RustBuffer
For complex types where it’s too fiddly or too unsafe to convert them into a special-purpose
C-compatible value, you can use this trait to implement lower()
in terms of write()
and
lift
in terms of read()
.
Required Associated Types
Required Methods
Implementations on Foreign Types
sourceimpl RustBufferFfiConverter for SystemTime
impl RustBufferFfiConverter for SystemTime
Support for passing timestamp values via the FFI.
Timestamps values are currently always passed by serializing to a buffer.
Timestamps are represented on the buffer by an i64 that indicates the direction and the magnitude in seconds of the offset from epoch, and a u32 that indicates the nanosecond portion of the offset magnitude. The nanosecond portion is expected to be between 0 and 999,999,999.
To build an epoch offset the absolute value of the seconds portion of the offset should be combined with the nanosecond portion. This is because the sign of the seconds portion represents the direction of the offset overall. The sign of the seconds portion can then be used to determine if the total offset should be added to or subtracted from the unix epoch.
sourceimpl RustBufferFfiConverter for Duration
impl RustBufferFfiConverter for Duration
Support for passing duration values via the FFI.
Duration values are currently always passed by serializing to a buffer.
Durations are represented on the buffer by a u64 that indicates the magnitude in seconds, and a u32 that indicates the nanosecond portion of the magnitude. The nanosecond portion is expected to be between 0 and 999,999,999.
sourceimpl<T: FfiConverter> RustBufferFfiConverter for Option<T>
impl<T: FfiConverter> RustBufferFfiConverter for Option<T>
Support for passing optional values via the FFI.
Optional values are currently always passed by serializing to a buffer.
We write either a zero byte for None
, or a one byte followed by the containing
item for Some
.
In future we could do the same optimization as rust uses internally, where the
None
option is represented as a null pointer and the Some
as a valid pointer,
but that seems more fiddly and less safe in the short term, so it can wait.
sourceimpl<T: FfiConverter> RustBufferFfiConverter for Vec<T>
impl<T: FfiConverter> RustBufferFfiConverter for Vec<T>
Support for passing vectors of values via the FFI.
Vectors are currently always passed by serializing to a buffer.
We write a i32
item count followed by each item in turn.
(It’s a signed type due to limits of the JVM).
Ideally we would pass Vec<u8>
directly as a RustBuffer
rather
than serializing, and perhaps even pass other vector types using a
similar struct. But that’s for future work.
sourceimpl<K: FfiConverter, V: FfiConverter> RustBufferFfiConverter for HashMap<K, V> where
K::RustType: Hash + Eq,
impl<K: FfiConverter, V: FfiConverter> RustBufferFfiConverter for HashMap<K, V> where
K::RustType: Hash + Eq,
Support for associative arrays via the FFI. Note that because of webidl limitations, the key must always be of the String type.
HashMaps are currently always passed by serializing to a buffer.
We write a i32
entries count followed by each entry (string
key followed by the value) in turn.
(It’s a signed type due to limits of the JVM).