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(). 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<Data>>where
Data: TrivialType,
MaybeData<Data>: IoType,
impl<'a, Data> Lent<'a, MaybeData<Data>>where
Data: TrivialType,
MaybeData<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<Element, RECOMMENDED_ALLOCATION>>where
Element: TrivialType,
VariableElements<Element, RECOMMENDED_ALLOCATION>: IoType,
impl<'a, Element, const RECOMMENDED_ALLOCATION: u32> Lent<'a, VariableElements<Element, RECOMMENDED_ALLOCATION>>where
Element: TrivialType,
VariableElements<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() or Self::set(), or the contents of T accept every bit
pattern.
Sourcepub fn get_mut(&mut self) -> Result<&mut T, ContractError>
pub fn get_mut(&mut self) -> Result<&mut T, 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(), which only exists for plain values, replaces them.
Lending them again doesn’t help either: methods generated by #[contract] reject outputs
with invalid initial contents with ContractError::BadInput.
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> Freeze for Lent<'a, T>
impl<'a, T> RefUnwindSafe for Lent<'a, T>
impl<'a, T> Unpin for Lent<'a, T>
impl<'a, T> UnsafeUnpin for Lent<'a, T>
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