Skip to main content

DataSource

Struct DataSource 

Source
pub struct DataSource<'a>(/* private fields */);
Expand description

The input to a wrapped operation: anything this crate knows how to feed into a WIT stream<u8>.

Operation methods take impl Into<DataSource<'_>>, so byte slices, owned buffers, and streams received from other components all work directly:

  • &[u8], &[u8; N], Vec<u8>, &Vec<u8>, Cow<'a, [u8]> — buffered sources. Owned data is moved and written whole, never copied; borrowed data is fed chunk by chunk through one reusable buffer, so a large input is never duplicated whole (the ABI’s per-chunk copy into an owned buffer is unavoidable).
  • StreamReader<u8> — passed through to the operation as-is, without buffering.
  • DataSource::from_buf (feature bytes) — fed chunk by chunk.
  • DataSource::from_reader (feature futures-io) — pumped incrementally; read failures surface as Error::Read.

§Warning: truncating producers

Dropping a stream’s writer is its only end-of-input signal and carries no verdict, so a producer that fails midway is indistinguishable on the wire from one that finished — the operation correctly computes over the delivered prefix. Buffer-backed sources own their whole input and are immune. For a StreamReader<u8> fed by another component, convey completeness in-band (e.g. length framing) or discard the result on producer failure. A DataSource::from_reader source is handled for you: its failure is observed locally and reported as Error::Read instead of the operation’s result.

Trait Implementations§

Source§

impl<'a> From<&'a [u8]> for DataSource<'a>

Source§

fn from(data: &'a [u8]) -> Self

Converts to this type from the input type.
Source§

impl<'a, const N: usize> From<&'a [u8; N]> for DataSource<'a>

Source§

fn from(data: &'a [u8; N]) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<&'a Vec<u8>> for DataSource<'a>

Source§

fn from(data: &'a Vec<u8>) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Cow<'a, [u8]>> for DataSource<'a>

Source§

fn from(data: Cow<'a, [u8]>) -> Self

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for DataSource<'_>

Source§

fn from(data: Vec<u8>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

impl<'a> !Freeze for DataSource<'a>

§

impl<'a> RefUnwindSafe for DataSource<'a>

§

impl<'a> Send for DataSource<'a>

§

impl<'a> Sync for DataSource<'a>

§

impl<'a> Unpin for DataSource<'a>

§

impl<'a> UnsafeUnpin for DataSource<'a>

§

impl<'a> UnwindSafe for DataSource<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Resource for T
where T: 'static,

§

type Rep = Option<T>

The type which is actually stored in-memory for this resource. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.