Skip to main content

OutputArg

Trait OutputArg 

Source
pub unsafe trait OutputArg<Target>
where Target: IoType,
{ // Required methods fn as_raw_output(&mut self) -> (NonNull<Target::PointerType>, u32, u32); unsafe fn set_output_size(&mut self, size: u32); }
Expand description

Memory that can be given to a method call as an #[output] of type Target.

A call can leave contents behind that are not a valid value of Target, for example when it fails halfway, so the contents must be parsed before they are accessed, unless every bit pattern is a valid value (see [AnyBitPattern]). Lent does this for memory whose contents need parsing.

A call gets the pointer, size and capacity from Self::as_raw_output(). Until self is used again, the call may write initialized bytes anywhere within the capacity, even if it fails. If it succeeds, the size it reports is set with Self::set_output_size().

§Safety

Self::as_raw_output() returns a pointer aligned for Target::PointerType, and a size that is valid for Target and doesn’t exceed the capacity it returns. The pointer is valid for writes of the capacity, but for reads only of the size, with that many bytes initialized: the bytes after them may be uninitialized and must not be read before they are written. While self stays exclusively borrowed after that, the memory is not accessed other than through the pointer. Whatever initialized bytes a call leaves within the size (the initial one or the last one set with Self::set_output_size()) are never accessed as Target without being parsed first, unless every bit pattern is a valid value of Target::PointerType.

Required Methods§

Source

fn as_raw_output(&mut self) -> (NonNull<Target::PointerType>, u32, u32)

Pointer to the contents, size and capacity to give to a call

Source

unsafe fn set_output_size(&mut self, size: u32)

Set the size that a successful call reported.

§Safety

size must be valid for Target (see [IoType::try_from_ptr()]) and not exceed the capacity, and that many bytes must be initialized.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<Arg> OutputArg<<Arg as IoTypeMut>::Target> for Arg
where Arg: IoTypeMut, <Arg::Target as IoType>::PointerType: AnyBitPattern,

Source§

impl<T> OutputArg<T> for Lent<'_, T>
where T: IoType,