#[repr(transparent)]pub struct Borrowed<'a, T: Abi> { /* private fields */ }
Expand description
A logically borrowed type that still retains the in-memory representation of the underlying type.
Note: this type is normally only used as a field to a struct. For function parameters, the Param
type, which builds on top of Borrowed
is used.
Borrowed
s can be thought of much like an Option<&T>
. The reason Borrowed
must be used instead of
Option<&T>
is because Borrowed
has the same in-memory layout as Option<T>
. This is necessary
for FFI calls that expect a logically borrowed type that, in-memory, looks like an owned type.
It’s important to note that owned values cannot be turn into Borrowed
s. After all, Borrowed
types are borrowed and not owned. Just as you cannot
turn pass a T
into function and get a &T
back, you cannot pass a T
into a function that ultimately expects a Borrowed<'a, T>
.
Implementations§
§impl<'a, T: Abi> Borrowed<'a, T>
impl<'a, T: Abi> Borrowed<'a, T>
pub fn new(item: Option<&'a T>) -> Self
pub fn new(item: Option<&'a T>) -> Self
Create a new Borrowed
value.
Normally, it is not necessary to use this function. Generally, there is a From
implementation
that allows you to call .into
to safely create a Borrowed
value.
pub fn none() -> Self
pub fn none() -> Self
Create a new null Borrowed
value.
pub fn abi(&self) -> T::Abi
pub fn abi(&self) -> T::Abi
Get the abi representation for this param
Note: the return value is only guranteed to be valid for the lifetime of &self