pub struct Lent<'a, T>where
T: IoType,{ /* private fields */ }Expand description
Memory lent to calls as an #[output], whose contents are parsed before they are accessed.
A call can leave contents behind that are not a valid value, for example when it fails halfway,
so the contents are only accessible through Self::get_mut(), which parses them once after
each call. Plain values can also be replaced with Self::set(), and containers emptied with
Self::clear(). Memory whose contents accept every bit pattern can be given to calls
directly, see OutputArg.
Created with Self::new() for a local value, with Lent::<MaybeData<'_, _>>::from_uninit()
or Lent::<VariableElements<'_, _>>::from_uninit() for a local container, and with
Env::lend_output() for an #[output] the method received.
Implementations§
Source§impl<'a, Data> Lent<'a, MaybeData<'a, Data>>where
Data: TrivialType,
MaybeData<'a, Data>: IoType,
impl<'a, Data> Lent<'a, MaybeData<'a, Data>>where
Data: TrivialType,
MaybeData<'a, Data>: IoType,
Sourcepub fn from_uninit(
uninit: &'a mut MaybeUninit<Data>,
size: &'a mut u32,
) -> Option<Self>
pub fn from_uninit( uninit: &'a mut MaybeUninit<Data>, size: &'a mut u32, ) -> Option<Self>
Lend a local [MaybeData] over uninitialized memory, like [MaybeData::from_uninit()].
Returns None if size != 0.
Source§impl<'a, Element, const RECOMMENDED_ALLOCATION: u32> Lent<'a, VariableElements<'a, Element, RECOMMENDED_ALLOCATION>>where
Element: TrivialType,
VariableElements<'a, Element, RECOMMENDED_ALLOCATION>: IoType,
impl<'a, Element, const RECOMMENDED_ALLOCATION: u32> Lent<'a, VariableElements<'a, Element, RECOMMENDED_ALLOCATION>>where
Element: TrivialType,
VariableElements<'a, Element, RECOMMENDED_ALLOCATION>: IoType,
Sourcepub fn from_uninit(
uninit: &'a mut [MaybeUninit<Element>],
size: &'a mut u32,
) -> Option<Self>
pub fn from_uninit( uninit: &'a mut [MaybeUninit<Element>], size: &'a mut u32, ) -> Option<Self>
Lend a local [VariableElements] over uninitialized memory, like
[VariableElements::from_uninit()].
Returns None if size != 0 or if the buffer is larger than u32::MAX bytes.
Source§impl<'a, T> Lent<'a, T>where
T: IoType,
impl<'a, T> Lent<'a, T>where
T: IoType,
Sourcepub unsafe fn from_mut_unchecked(value: &'a mut T) -> Self
pub unsafe fn from_mut_unchecked(value: &'a mut T) -> Self
Lend value, which is only borrowed for 'a, rather than until the method returns like
with Env::lend_output().
§Safety
After the returned Lent was given to a call, value may hold contents that are not a
valid value. Once the Lent is no longer used, the contents of value must not be accessed
without being parsed first, unless the last use of the Lent after its last call was a
successful Self::get_mut(), Self::set() or Self::clear(), or the contents of T
accept every bit pattern.
Sourcepub fn get_mut(&mut self) -> Result<T::Reborrowed<'_>, ContractError>
pub fn get_mut(&mut self) -> Result<T::Reborrowed<'_>, ContractError>
Exclusive access to the contents, which are parsed once after each call.
Repeated calls without a call in between don’t parse the contents again. Returns
ContractError::BadOutput if they are not a valid value of T. They then stay
inaccessible until Self::set() replaces a plain value or Self::clear() empties a
container. Lending them again doesn’t help either: methods generated by #[contract] reject
outputs with invalid initial contents with ContractError::BadInput.
A plain value is returned as &mut T. A container is returned as a new view of the lent
memory that only lives while self is borrowed (see [IoType::reborrow_mut()]). Code that
replaces it, for example with a view of other memory, doesn’t change what self lends to
calls.
Source§impl<T> Lent<'_, T>where
T: IoTypeOptional,
impl<T> Lent<'_, T>where
T: IoTypeOptional,
Sourcepub fn clear(&mut self) -> T::Reborrowed<'_>
pub fn clear(&mut self) -> T::Reborrowed<'_>
Empty the contents, which makes them a valid value whatever calls left behind.
The size becomes 0 and the capacity stays the same. This makes a container accessible
again after Self::get_mut() returned ContractError::BadOutput, so the memory can be
lent to another call, even if it was lent with Env::lend_output() and can’t be lent
anew. Since a call gets the contents of an #[output] as its initial contents, this also
gives the next call an empty container rather than what the previous call left behind.
Returns the emptied container like Self::get_mut() does.
Trait Implementations§
Auto Trait Implementations§
impl<'a, T> !Send for Lent<'a, T>
impl<'a, T> !Sync for Lent<'a, T>
impl<'a, T> !UnwindSafe for Lent<'a, T>
impl<'a, T> Forget for Lent<'a, T>
impl<'a, T> Freeze for Lent<'a, T>
impl<'a, T> Move for Lent<'a, T>
impl<'a, T> RefUnwindSafe for Lent<'a, T>where
T: RefUnwindSafe,
<T as IoType>::PointerType: RefUnwindSafe,
impl<'a, T> Unpin for Lent<'a, T>
impl<'a, T> UnsafeUnpin for Lent<'a, T>where
T: UnsafeUnpin,
*const T is !null: UnsafeUnpin,
PhantomData<&'a mut T>: UnsafeUnpin,
*const <T as IoType>::PointerType is !null: UnsafeUnpin,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more