Skip to content

Commit

Permalink
Merge pull request #81 from TD-Sky/re-restore
Browse files Browse the repository at this point in the history
Describe how to retry restoring when encountering `RestoreCollision` error
  • Loading branch information
Byron authored Oct 8, 2023
2 parents 24e0cb6 + 554c273 commit c87a946
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,32 @@ pub mod os_limited {
///
/// # Example
///
/// Basic usage:
///
/// ```
/// use std::fs::File;
/// use trash::os_limited::{list, restore_all};
///
/// let filename = "trash-restore_all-example";
/// File::create(filename).unwrap();
/// restore_all(list().unwrap().into_iter().filter(|x| x.name == filename)).unwrap();
/// std::fs::remove_file(filename).unwrap();
/// ```
///
/// Retry restoring when encountering [`RestoreCollision`] error:
///
/// ```no_run
/// use trash::os_limited::{list, restore_all};
/// use trash::Error::RestoreCollision;
///
/// let items = list().unwrap();
/// if let Err(RestoreCollision { path, mut remaining_items }) = restore_all(items) {
/// // keep all except the one(s) that couldn't be restored
/// remaining_items.retain(|e| e.original_path() != path);
/// restore_all(remaining_items).unwrap();
/// }
/// ```
///
/// [`RestoreCollision`]: Error::RestoreCollision
/// [`RestoreTwins`]: Error::RestoreTwins
pub fn restore_all<I>(items: I) -> Result<(), Error>
Expand Down

0 comments on commit c87a946

Please sign in to comment.