pub struct StreamReducer { /* private fields */ }Implementations§
Source§impl StreamReducer
impl StreamReducer
Sourcepub fn new(rule: &Rule) -> Result<Self, String>
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}Sourcepub fn push(&mut self, chunk: &[u8])
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}Sourcepub fn finish(
self,
success: bool,
recovery: Option<RecoveryMarker<'_>>,
) -> Vec<u8> ⓘ
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§
Auto Trait Implementations§
impl Freeze for StreamReducer
impl RefUnwindSafe for StreamReducer
impl Send for StreamReducer
impl Sync for StreamReducer
impl Unpin for StreamReducer
impl UnsafeUnpin for StreamReducer
impl UnwindSafe for StreamReducer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more