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(featurebytes) — fed chunk by chunk.DataSource::from_reader(featurefutures-io) — pumped incrementally; read failures surface asError::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.