# [−][src]Crate same_file

This crate provides a safe and simple cross platform way to determine whether two file paths refer to the same file or directory.

Most uses of this crate should be limited to the top-level `is_same_file` function, which takes two file paths and returns true if they refer to the same file or directory:

    use same_file::is_same_file;

    assert!(is_same_file("/bin/sh", "/usr/bin/sh")?);

Additionally, this crate provides a `Handle` type that permits a more efficient equality check depending on your access pattern. For example, if one wanted to check whether any path in a list of paths corresponded to the process' stdout handle, then one could build a handle once for stdout. The equality check for each file in the list then only requires one stat call instead of two. The code might look like this:

    use same_file::Handle;

    let candidates = &[
        "examples/is_same_file.rs",
        "examples/is_stderr.rs",
        "examples/stderr",
    ];
    let stdout_handle = Handle::stdout()?;
    for candidate in candidates {
        let handle = Handle::from_path(candidate)?;
        if stdout_handle == handle {
            println!("{:?} is stdout!", candidate);
        } else {
            println!("{:?} is NOT stdout!", candidate);
        }
    }

See `examples/is_stderr.rs` for a runnable example and compare the output of:

- `cargo run --example is_stderr 2> examples/stderr` and
- `cargo run --example is_stderr`.

## Structs

Handle | A handle to a file that can be tested for equality with other handles.

## Functions

is_same_file | Returns true if the two file paths may correspond to the same file.

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)