pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<LinkOrCopy> {
    let p = p.as_ref();
    let q = q.as_ref();
    if q.exists() {
        fs::remove_file(&q)?;
    }

    match fs::hard_link(p, q) {
        Ok(()) => Ok(LinkOrCopy::Link),
        Err(_) => {
            match fs::copy(p, q) {
                Ok(_) => Ok(LinkOrCopy::Copy),
                Err(e) => Err(e)
            }
        }
    }
}
/// Copy `p` into `q`, preferring to use hard-linking if possible. If
/// `q` already exists, it is removed first.
/// The result indicates which of the two operations has been performed.
Copy `p` into `q`, preferring to use hard-linking if possible. If
`q` already exists, it is removed first.
The result indicates which of the two operations has been performed.
Copy ` p ` into ` q ` preferring to use hard - linking if possible . If ` q ` already exists it is removed first . The result indicates which of the two operations has been performed .
pub fn link_or_copy<P: AsRef<Path>, Q: AsRef<Path>>(p: P, q: Q) -> io::Result<LinkOrCopy> {
    let p = p.as_ref();
    let q = q.as_ref();
    if q.exists() {
        fs::remove_file(&q)?;
    }
    match fs::hard_link(p, q) {
        Ok(()) => Ok(LinkOrCopy::Link),
        Err(_) => {
            match fs::copy(p, q) {
                Ok(_) => Ok(LinkOrCopy::Copy),
                Err(e) => Err(e)
            }
        }
    }
}
pub fn link_or_copy < P : AsRef < Path > , Q : AsRef < Path > > ( p : P , q : Q ) -> io :: Result < LinkOrCopy > { let p = p . as_ref ( ) ; let q = q . as_ref ( ) ; if q . exists ( ) { fs :: remove_file ( & q ) ? ; } match fs :: hard_link ( p , q ) { Ok ( ( ) ) => Ok ( LinkOrCopy :: Link ) , Err ( _ ) => { match fs :: copy ( p , q ) { Ok ( _ ) => Ok ( LinkOrCopy :: Copy ) , Err ( e ) => Err ( e ) } } } }
Copy `p` into `q`, preferring to use hard-linking if possible.
Copy ` p ` into ` q ` preferring to use hard - linking if possible .
p
P
q
Q
p
P
q
Q