Docs.rs
  • same-file-1.0.6
    • same-file 1.0.6
    • Permalink
    • Docs.rs crate page
    • Unlicense/MIT
    • Links
    • Homepage
    • Repository
    • crates.io
    • Source
    • Owners
    • BurntSushi
    • Dependencies
      • doc-comment ^0.3 dev
      • winapi-util ^0.1.1 normal
    • Versions
    • 100% of the crate is documented
  • Platform
    • i686-pc-windows-msvc
    • i686-unknown-linux-gnu
    • x86_64-apple-darwin
    • x86_64-pc-windows-msvc
    • x86_64-unknown-linux-gnu
  • Feature flags
  • docs.rs
    • About docs.rs
    • Privacy policy
  • Rust
    • Rust website
    • The Book
    • Standard Library API Reference
    • Rust by Example
    • The Cargo Guide
    • Clippy Documentation

Crate same_file

same_file1.0.6

  • All Items

Crate Items

  • Structs
  • Functions

Crates

  • same_file

Crate same_file

Source
Expand description

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.

Results

Settings
Help
    struct
    same_file::Handle
    A handle to a file that can be tested for equality with …
    method
    same_file::Handle::into_raw_fd
    Handle -> RawFd
    method
    same_file::Handle::dev
    &Handle -> u64
    Return the underlying device number of this handle.
    method
    same_file::Handle::ino
    &Handle -> u64
    Return the underlying inode number of this handle.
    method
    same_file::Handle::as_raw_fd
    &Handle -> RawFd
    method
    same_file::Handle::as_file
    &Handle -> &File
    Return a reference to the underlying file.
    method
    same_file::Handle::eq
    &Handle, &Handle -> bool
    method
    same_file::Handle::fmt
    &Handle, &mut Formatter -> Result
    method
    same_file::Handle::as_file_mut
    &mut Handle -> &mut File
    Return a mutable reference to the underlying file.
    method
    same_file::Handle::hash
    &Handle, &mut __H -> ()
    method
    same_file::Handle::stdin
    -> Result<Handle>
    Construct a handle from stdin.
    method
    same_file::Handle::stderr
    -> Result<Handle>
    Construct a handle from stderr.
    method
    same_file::Handle::stdout
    -> Result<Handle>
    Construct a handle from stdout.
    method
    same_file::Handle::from_file
    File -> Result<Handle>
    Construct a handle from a file.
    method
    same_file::Handle::from_path
    P -> Result<Handle>
    Construct a handle from a path.