Skip to content

Commit

Permalink
Update doc
Browse files Browse the repository at this point in the history
  • Loading branch information
brmmm3 committed Apr 13, 2024
1 parent 452d084 commit ee412b5
Showing 1 changed file with 54 additions and 6 deletions.
60 changes: 54 additions & 6 deletions scandir/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ For the API see:

## Examples

Get statistics of a directory:
`Collect` examples:

```rust
use scandir::Count;

// Get basic statistics
// collect() starts the worker thread and waits until it has finished. The line below is blocking.
println!(Count::new("/usr")?.collect()?);
// Get extended statistics
println!(Count::new("/usr", return_type=ReturnType.Ext)?.collect()?);
Expand All @@ -46,24 +46,72 @@ instance.stop(); // If you want to cancel the task
instance.join(); // Wait for the instance to finish.
```

```rust
let mut instance = Count::new(&path)?;
instance.start()?;
loop {
if !instance.busy() {
break;
}
// Do something
thread::sleep(Duration::from_millis(10));
}
// collect() immediately returns because the worker thread has already finished.
let statistics = instance.collect()?;
```

`Walk` example:

```rust
use scandir::Walk;

// Get basic statistics
// Get basic file tree
println!(Walk::new("/usr")?.collect()?);
// Get extended statistics
// Get file tree with extended file type identification. This is slower.
println!(Walk::new("/usr", return_type=ReturnType.Ext)?.collect()?);
```

If you want to have intermediate results, e.g. you want to show the progress to the user, the use the example below.

```rust
let mut instance = Walk::new(&path, None)?;
instance.start()?;
loop {
if !instance.busy() {
break;
}
let new_results = instance.results(true);
// Do something
thread::sleep(Duration::from_millis(10));
}
// collect() immediately returns because the worker thread has already finished.
let results = instance.collect()?;
```

`Scandir` example:

```rust
use scandir::Scandir;

// Get basic statistics
// Get basic file metadata
println!(Scandir::new("/usr")?.collect()?);
// Get extended statistics
// Get extended file metadata
println!(Scandir::new("/usr", return_type=ReturnType.Ext, None)?.collect()?);
```

If you want to have intermediate results, e.g. you want to show the progress to the user, the use the example below.

```rust
let mut instance = Scandir::new(&path, None)?;
instance.start()?;
loop {
if !instance.busy() {
break;
}
let new_results = instance.results(true);
// Do something
thread::sleep(Duration::from_millis(10));
}
// collect() immediately returns because the worker thread has already finished.
let results = instance.collect()?;
```

0 comments on commit ee412b5

Please sign in to comment.