Struct uniffi::ForeignBytes

source ·
pub struct ForeignBytes { /* private fields */ }
Expand description

Support for reading a slice of foreign-language-allocated bytes over the FFI.

Foreign language code can pass a slice of bytes by providing a data pointer and length, and this struct provides a convenient wrapper for working with that pair. Naturally, this can be tremendously unsafe! So here are the details:

  • The foreign language code must ensure the provided buffer stays alive and unchanged for the duration of the call to which the ForeignBytes struct was provided.

To work with the bytes in Rust code, use as_slice() to view the data as a &[u8].

Implementation note: all the fields of this struct are private and it has no constructors, so consuming crates cant create instances of it. If you’ve got a ForeignBytes, then you received it over the FFI and are assuming that the foreign language code is upholding the above invariants.

This struct is based on ByteBuffer from the ffi-support crate, but modified to give a read-only view of externally-provided bytes.

Implementations§

Creates a ForeignBytes from its constituent fields.

This is intended mainly as an internal convenience function and should not be used outside of this module.

Safety

You must ensure that the raw parts uphold the documented invariants of this class.

View the foreign bytes as a &[u8].

Panics

Panics if the provided struct has a null pointer but non-zero length. Panics if the provided length is negative.

Get the length of this slice of bytes.

Panics

Panics if the provided length is negative.

Returns true if the length of this slice of bytes is 0.

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

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

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.