Hi,
In the crate fs_extra there is a method copy_items_with_progress:
https://docs.rs/fs_extra/1.2.0/fs_extra/fn.copy_items_with_progress.html
And assuming that I have that function running in a separate thread, how to actually cancel the execution of this function?
This is my code so far:
siv.add_layer(
Dialog::around(
ProgressBar::new()//this will be the progress of copy_items_with_progress method
// We need to know how many ticks represent a full bar.
.range(0, selected_path_from.metadata().unwrap().size() as usize)
.with_task(move |counter| {// This closure will be called in a separate thread.
let options = fs_extra::dir::CopyOptions::new();
/*The below is the handler that will be called by copy_items_with_progress*/
let handle = |process_info: fs_extra::TransitProcess| {
let percent = (process_info.file_bytes_copied as f64 / process_info.file_total_bytes as f64) * 100_000_f64;
counter.tick(percent as usize);
fs_extra::dir::TransitProcessResult::ContinueOrAbort
};
//Here is the actuall call to copy_items_with_progress, which calls the handler above and which I want to be able to cancell
fs_extra::copy_items_with_progress(&vec![selected_path_from], &selected_path_to, &options, handle).unwrap();
})
)
/*Here I can only pass closure that takes cursive as an argument*/
.button("Cancel", cancel_operation),
);
Thanks