#[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.
Borroweds 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 Borroweds. 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
Trait Implementations
Auto Trait Implementations
impl<'a, T> RefUnwindSafe for Borrowed<'a, T> where
<T as Abi>::Abi: RefUnwindSafe,
impl<'a, T> Send for Borrowed<'a, T> where
<T as Abi>::Abi: Send,
impl<'a, T> Sync for Borrowed<'a, T> where
<T as Abi>::Abi: Sync,
impl<'a, T> Unpin for Borrowed<'a, T> where
<T as Abi>::Abi: Unpin,
impl<'a, T> UnwindSafe for Borrowed<'a, T> where
<T as Abi>::Abi: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more