pub trait Slicer:
Send
+ Sync
+ Debug {
// Required methods
fn id(&self) -> SlicerId;
fn slice<'life0, 'life1, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
) -> Pin<Box<dyn Future<Output = Result<Slice, SliceError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait;
// Provided methods
fn counter(&self) -> &dyn TokenCount { ... }
fn minimum_cap(&self) -> usize { ... }
fn condense<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
store: &'life2 dyn Store,
) -> Pin<Box<dyn Future<Output = Result<Condensate, SliceError>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait { ... }
}Expand description
Required Methods§
Sourcefn id(&self) -> SlicerId
fn id(&self) -> SlicerId
Which slicer this is, and at what version.
Recorded into every condensate, so re-slicing the same raw output later can be checked against the version that originally produced it.
Sourcefn slice<'life0, 'life1, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
) -> Pin<Box<dyn Future<Output = Result<Slice, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn slice<'life0, 'life1, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
) -> Pin<Box<dyn Future<Output = Result<Slice, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Produce the summary. The part an implementation writes.
Must be a pure function of (raw, cap) — see the module documentation
on determinism.
§Errors
SliceError::Unsuitable if this slicer does not handle the input.
Provided Methods§
Sourcefn counter(&self) -> &dyn TokenCount
fn counter(&self) -> &dyn TokenCount
How this slicer counts tokens.
Defaults to Estimate. Override to inject a real tokeniser.
Sourcefn minimum_cap(&self) -> usize
fn minimum_cap(&self) -> usize
The least a summary from this slicer can cost.
Used to turn an impossible cap into SliceError::CapTooSmall before
any work happens, so the author is told their step’s window is too small
rather than handed a mysterious over-cap failure.
Sourcefn condense<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
store: &'life2 dyn Store,
) -> Pin<Box<dyn Future<Output = Result<Condensate, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn condense<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
raw: &'life1 Raw,
cap: usize,
store: &'life2 dyn Store,
) -> Pin<Box<dyn Future<Output = Result<Condensate, SliceError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
Preserve the original, slice it, and check the result fits.
In that order, and the order matters: the raw bytes reach the store before anything is dropped, so a slicer that fails part-way through still leaves the original recoverable.
§Errors
SliceError::Store if the original could not be preserved,
SliceError::CapTooSmall if the cap cannot hold a summary,
SliceError::OverCap if the slicer overran it, or whatever
slice returned.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".