Skip to main content

StreamReducer

Struct StreamReducer 

Source
pub struct StreamReducer { /* private fields */ }

Implementations§

Source§

impl StreamReducer

Source

pub fn new(rule: &Rule) -> Result<Self, String>

Build bounded state for one validated reduction rule.

§Errors

Returns an error when the supplied rule is not a complete reduction rule.

Examples found in repository?
examples/rule_benchmark.rs (line 133)
124fn benchmark_stream() -> Result<(f64, usize), String> {
125    let mut registry = Registry::builtins_only();
126    let Selection::Reduce(selected) = registry.select(&["rg".to_owned(), "needle".to_owned()])?
127    else {
128        return Err("stream benchmark rule was not selected".to_owned());
129    };
130    let chunk = b"src/file.rs:42:matching line with useful context\n".repeat(160);
131    let bytes = 1_024 * 1_024 * 1_024;
132    let started = Instant::now();
133    let mut reducer = StreamReducer::new(&selected.rule)?;
134    let mut processed = 0;
135    while processed < bytes {
136        reducer.push(black_box(&chunk));
137        processed += chunk.len();
138    }
139    black_box(reducer.finish(true, None));
140    let processed = u32::try_from(processed)
141        .map_err(|_| "stream benchmark byte count does not fit u32".to_owned())?;
142    let throughput = f64::from(processed) / 1_000_000.0 / started.elapsed().as_secs_f64();
143    Ok((throughput, configured_memory_bound(&selected.rule)?))
144}
Source

pub fn push(&mut self, chunk: &[u8])

Examples found in repository?
examples/rule_benchmark.rs (line 136)
124fn benchmark_stream() -> Result<(f64, usize), String> {
125    let mut registry = Registry::builtins_only();
126    let Selection::Reduce(selected) = registry.select(&["rg".to_owned(), "needle".to_owned()])?
127    else {
128        return Err("stream benchmark rule was not selected".to_owned());
129    };
130    let chunk = b"src/file.rs:42:matching line with useful context\n".repeat(160);
131    let bytes = 1_024 * 1_024 * 1_024;
132    let started = Instant::now();
133    let mut reducer = StreamReducer::new(&selected.rule)?;
134    let mut processed = 0;
135    while processed < bytes {
136        reducer.push(black_box(&chunk));
137        processed += chunk.len();
138    }
139    black_box(reducer.finish(true, None));
140    let processed = u32::try_from(processed)
141        .map_err(|_| "stream benchmark byte count does not fit u32".to_owned())?;
142    let throughput = f64::from(processed) / 1_000_000.0 / started.elapsed().as_secs_f64();
143    Ok((throughput, configured_memory_bound(&selected.rule)?))
144}
Source

pub fn finish( self, success: bool, recovery: Option<RecoveryMarker<'_>>, ) -> Vec<u8> ⓘ

Examples found in repository?
examples/rule_benchmark.rs (line 139)
124fn benchmark_stream() -> Result<(f64, usize), String> {
125    let mut registry = Registry::builtins_only();
126    let Selection::Reduce(selected) = registry.select(&["rg".to_owned(), "needle".to_owned()])?
127    else {
128        return Err("stream benchmark rule was not selected".to_owned());
129    };
130    let chunk = b"src/file.rs:42:matching line with useful context\n".repeat(160);
131    let bytes = 1_024 * 1_024 * 1_024;
132    let started = Instant::now();
133    let mut reducer = StreamReducer::new(&selected.rule)?;
134    let mut processed = 0;
135    while processed < bytes {
136        reducer.push(black_box(&chunk));
137        processed += chunk.len();
138    }
139    black_box(reducer.finish(true, None));
140    let processed = u32::try_from(processed)
141        .map_err(|_| "stream benchmark byte count does not fit u32".to_owned())?;
142    let throughput = f64::from(processed) / 1_000_000.0 / started.elapsed().as_secs_f64();
143    Ok((throughput, configured_memory_bound(&selected.rule)?))
144}

Trait Implementations§

Source§

impl Debug for StreamReducer

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.