feat(rust)!: use ops::ControlFlow as parse and query progress return value
Instead of returning an undocumented boolean flag, use a core::ops::ControlFlow object. At the expense of being a bit more verbose, this is a type that should be self-explanatory in the context of a callback, as an indication of whether to continue processing or stop.
This commit is contained in:
parent
57e2f41f42
commit
937dcf5fd1
6 changed files with 120 additions and 47 deletions
|
|
@ -1,6 +1,7 @@
|
|||
use std::{
|
||||
fmt, fs,
|
||||
io::{self, Write},
|
||||
ops::ControlFlow,
|
||||
path::{Path, PathBuf},
|
||||
sync::atomic::{AtomicUsize, Ordering},
|
||||
time::{Duration, Instant},
|
||||
|
|
@ -357,15 +358,15 @@ pub fn parse_file_at_path(
|
|||
let progress_callback = &mut |_: &ParseState| {
|
||||
if let Some(cancellation_flag) = opts.cancellation_flag {
|
||||
if cancellation_flag.load(Ordering::SeqCst) != 0 {
|
||||
return true;
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
}
|
||||
|
||||
if opts.timeout > 0 && start_time.elapsed().as_micros() > opts.timeout as u128 {
|
||||
return true;
|
||||
return ControlFlow::Break(());
|
||||
}
|
||||
|
||||
false
|
||||
ControlFlow::Continue(())
|
||||
};
|
||||
|
||||
let parse_opts = ParseOptions::new().progress_callback(progress_callback);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue